home *** CD-ROM | disk | FTP | other *** search
/ AGA Toolkit '97 / The AGA Toolkit '97.iso / text / misc / port / oldstuff / portsource.lha / Port200.S < prev   
Encoding:
Text File  |  1994-06-26  |  77.4 KB  |  3,889 lines

  1. Code020      =    1        ; Define for 020 code, comment for 000.
  2. ;Debug        =    1        ; Define for Say() & ShowReg() macros.
  3.  
  4.     IFND    Code020
  5.     MACHINE    68000
  6.     ENDC
  7.     IFD    Code020
  8.     MACHINE    68020
  9.     ENDC
  10.  
  11.     XREF    StrCat
  12.     XREF    StrCmp
  13.     XREF    StrCpy
  14.     XREF    StrChr
  15.     XREF    StrEnd
  16.     XREF    StrFirstNum
  17.     XREF    StrLFCat
  18.     XREF    StrLen
  19.     XREF    StrNCmp
  20.     XREF    StrNumCat
  21.     XREF    StrToNum
  22.  
  23.     XDEF    Num2ASCII
  24.  
  25. ; Last CodeError code used: 4
  26.  
  27. ; During the translation loop:
  28. ; A0 = Pointer to source data
  29. ; A1 = Pointer to destination data
  30. ; A2 = Pointer to space buffer
  31. ; A3 = Pointer to translation table
  32. ; A4 = Pointer to InterNet header stripper buffer.
  33. ; A5 = Data base pointer. (Ptr to DT)
  34.  
  35. ; D0 = Current char
  36. ; D1 = Counter of bytes left in the source buffer.
  37. ; D2 = Counter of converted bytes in the destination buffer.
  38. ; D3 = Counter of overall converted bytes.
  39.  
  40.     INCDIR    "INCLUDE:"
  41.     INCLUDE    "Darkness.I"
  42.     INCLUDE    "Exec.Offsets"
  43.     INCLUDE    "Dos.Offsets"
  44.     INCLUDE "exec/types.i"
  45.     INCLUDE    "exec/execbase.i"
  46.     INCLUDE    "exec/memory.i"
  47.     INCLUDE    "hardware/intbits.i"
  48.     INCLUDE    "dos/dos.i"
  49.     INCLUDE    "dos/dosasl.i"
  50.     INCLUDE "libraries/ppbase.i"
  51.     INCLUDE "libraries/powerpacker_lib.i"
  52.     INCLUDE    "utility/tagitem.i"
  53.  
  54.     STRUCTURE    FileLink,0
  55.     LONG    fl_Next
  56.     LONG    fl_Size
  57.     STRUCT    fl_FullName,256
  58.     STRUCT    fl_FileName,256
  59.     LABEL    fl_SIZEOF
  60.  
  61. ; Modes which want CRs must be negative.
  62. MODE_TOPC    =    -1
  63. MODE_TOSF7    =    -2
  64.  
  65. MODE_FROMPC    =     1
  66. MODE_FROMSF7    =     2
  67. MODE_TOUPCASE    =     3
  68. MODE_TOLOWCASE    =     4
  69. MODE_TONULL    =     5
  70. MODE_TOASCII    =     7
  71. MODE_COMBINED    =     8
  72.  
  73. SIZE_MAXNEW    =    16        ; Maximum size change in one cycle.
  74.  
  75. CR        =    13
  76. LF        =    10
  77. TAB        =     9
  78.  
  79. TRUE        =     -1
  80. FALSE        =     0
  81.  
  82. ANSI_CLEAR    =     0        ; No ANSI code currently active.
  83. ANSI_WAIT    =     1        ; ESC found, but no "[" yet.
  84. ANSI_CODE    =     2        ; In progress of skipping the code.
  85.  
  86. ; A macro to call a library routine.
  87.  
  88. Call    MACRO
  89.     move.l    _\1Base,a6
  90.     jsr    _LVO\2(a6)
  91.     ENDM
  92.  
  93. BToLong    MACRO
  94.     IFD    Code020            ; Convert TabSize
  95.     extb.l    \1
  96.     ENDC
  97.     IFND    Code020
  98.     ext.w    \1
  99.     ext.l    \1
  100.     ENDC
  101.     ENDM
  102.  
  103. SaveR    MACRO
  104.     movem.l    d0-d7/a0-a6,-(sp)
  105.     ENDM
  106.  
  107. LoadR    MACRO
  108.     movem.l    (sp)+,d0-d7/a0-a6
  109.     ENDM
  110.  
  111. Say    MACRO
  112.     IFD    Debug
  113.     SaveR
  114.     lea    DebugBuf,a0
  115.     lea    .Shit\@,a1
  116.     bsr    StrCpy
  117.     lea    DebugBuf,a0
  118.     bsr    StrLFCat
  119.     move.l    #DebugBuf,d2
  120.     bsr    PrintText
  121.     LoadR
  122.     bra    .Skip\@
  123.  
  124. .Shit\@:
  125.     dc.b    \1,0
  126.  
  127.     EVEN
  128.  
  129. .Skip\@:
  130.     ENDC
  131.     ENDM
  132.  
  133. ShowPtr    MACRO
  134.     IFD    Debug
  135.     SaveR
  136.     move.l    \1,d2
  137.     bsr    PrintText
  138.     LoadR
  139.     ENDC
  140.     ENDM
  141.  
  142. ShowReg    MACRO
  143.     IFD    Debug
  144.     SaveR
  145.     lea    .Shit\@,a0
  146.     clr.b    (a0)
  147.     move.l    \1,d0
  148.     bsr    StrNumCat
  149.     lea    .Shit\@,a0
  150.     bsr    StrLFCat
  151.     move.l    #.Shit\@,d2
  152.     bsr    PrintText
  153.     LoadR
  154.     bra    .Skip\@
  155.  
  156. .Shit\@:
  157.     ds.b    256
  158.  
  159.     EVEN
  160.  
  161. .Skip\@:
  162.     ENDC
  163.     ENDM
  164.  
  165. ProgStart:
  166.     move.l    sp,OldStack
  167.     lea    DT,a5
  168.     clr.b    -1(a0,d0.w)
  169.     move.l    a0,-(sp)
  170.     add.l    d0,a0
  171.     subq.l    #1,a0
  172.  
  173.     lea    _DosName,a1
  174.     moveq    #37,d0
  175.     Call    Exec,OpenLibrary
  176.     move.l    d0,_DosBase
  177.     beq    Err_NewerKickNeeded
  178.  
  179.     IFD    Code020
  180.     move.l    _ExecBase,a6        ; Tests if we have 68020.
  181.     move.w    AttnFlags(a6),d0
  182.     btst.w    #AFB_68020,d0
  183.     beq    Err_OldProcessor
  184.     ENDC
  185.  
  186.     Call    Dos,Output        ; Find the Shell output stream.
  187.     move.l    d0,(a5,OutStruct-DT)
  188.  
  189.     move.l    #Text_Header,d2
  190.     bsr    PrintText
  191.  
  192.     lea    PPName,a1        ; Open PP library if we have it.
  193.     moveq    #35,d0            ; If change to higher check 'PPNeed'.
  194.     Call    Exec,OpenLibrary
  195.     move.l    d0,_PPBase
  196.  
  197.     move.l    4.w,a6            ; Set up the interrupt.
  198.     move.l    VBlankFrequency(a6),(a5,TickDelay-DT)
  199.  
  200.     moveq    #INTB_VERTB,d0        ; Add the counter interrupt.
  201.     lea    VertBInterrupt,a1
  202.     Call    Exec,AddIntServer
  203.     st    (a5,Flag_IntActive-DT)
  204.  
  205.     move.l    (a7),a0            ; CommandStart
  206.     tst.b    (a0)            ; If blank commandline, instructions.
  207.     beq.w    HelpText
  208.     cmp.b    #"?",(a0)
  209.     beq.w    HelpText
  210.  
  211.     bsr    LoadPrefs        ; Load user preferences.
  212.     move.l    (a7)+,a0        ; CommandStart
  213.  
  214. ParseStart:
  215.     cmp.b    #"-",(a0)
  216.     beq.b    CheckOption
  217.  
  218. Parse:
  219.     cmp.b    #" ",1(a0)        ; At least one space after option
  220.     bne    Err_BadComLine
  221.     cmp.b    #"p",(a0)
  222.     beq.w    FromPCMode
  223.     cmp.b    #"P",(a0)
  224.     beq.w    ToPCMode
  225.     cmp.b    #"c",(a0)
  226.     beq.w    CombinedMode
  227.     cmp.b    #"s",(a0)
  228.     beq.w    FromSF7Mode
  229.     cmp.b    #"S",(a0)
  230.     beq.w    ToSF7Mode
  231.     cmp.b    #"u",(a0)
  232.     beq.w    ToUpCaseMode
  233.     cmp.b    #"l",(a0)
  234.     beq.w    ToLowCaseMode
  235.     cmp.b    #"n",(a0)
  236.     beq.w    ModeToNull
  237.     cmp.b    #"o",(a0)
  238.     beq.w    ModeToOnlyASCII
  239.     bra.w    Err_BadComLine
  240.  
  241. CheckOption:
  242.     cmp.b    #"a",1(a0)
  243.     beq.b    Opt_AStrip
  244.     cmp.b    #"e",1(a0)
  245.     beq.b    Opt_MakeEOLs
  246.     cmp.b    #"i",1(a0)
  247.     beq.b    Opt_INStrip
  248.     cmp.b    #"n",1(a0)
  249.     beq.b    Opt_NoCutSpace
  250.     cmp.b    #"p",1(a0)
  251.     beq    Opt_PPackOut
  252.     cmp.b    #"l",1(a0)
  253.     beq    Opt_LhAPackOut
  254.     cmp.b    #"?",1(a0)
  255.     beq    Credits
  256.     cmp.b    #"t",1(a0)
  257.     beq    Opt_TabConv
  258.     cmp.b    #"s",1(a0)
  259.     beq    Opt_SpaceConv
  260.     cmp.b    #"b",1(a0)
  261.     beq    Opt_NoBufferMode
  262.     bra    Err_BadComLine        ; Unknown option, report error.
  263.  
  264. Opt_AStrip:
  265.     cmp.b    #"!",2(a0)
  266.     beq.b    .Off
  267.     addq.l    #2,a0
  268.     st    (a5,Flag_AStrip-DT)
  269.     bra    Opt_Next
  270.  
  271. .Off:
  272.     addq.l    #3,a0
  273.     clr.b    (a5,Flag_AStrip-DT)
  274.     bra    Opt_Next
  275.  
  276. Opt_INStrip:
  277.     addq.l    #3,a0
  278.     cmp.b    #"!",-1(a0)
  279.     beq.b    .Off
  280.     cmp.b    #"1",-1(a0)
  281.     beq.b    .PutInfo
  282.     cmp.b    #"2",-1(a0)
  283.     beq.b    .NoInfo
  284.     bra    Err_BadComLine
  285.  
  286. .Off:
  287.     clr.b    (a5,Flag_INStrip-DT)
  288.     bra.b    Opt_Next
  289.  
  290. .PutInfo:
  291.     move.b    #1,(a5,Flag_INStrip-DT)
  292.     bra.b    Opt_Next
  293.  
  294. .NoInfo:
  295.     move.b    #2,(a5,Flag_INStrip-DT)
  296.     bra.b    Opt_Next
  297.  
  298. Opt_NoCutSpace:
  299.     cmp.b    #"!",2(a0)
  300.     beq.b    .Off
  301.     tst.b    (a5,Size_MakeEOLs-DT)
  302.     bne    Err_BadLogic
  303.     st    (a5,Mode_NoCutSpace-DT)
  304.     addq.l    #2,a0
  305.     bra.w    Opt_Next
  306.  
  307. .Off:
  308.     addq.l    #3,a0
  309.     clr.b    (a5,Mode_NoCutSpace-DT)
  310.     bra    Opt_Next
  311.  
  312. Opt_LhAPackOut:
  313.     cmp.b    #"!",2(a0)
  314.     beq.b    .Off
  315.     tst.b    (a5,Flag_CrunchBuf-DT)
  316.     bne    Err_BadLogic
  317.     addq.l    #2,a0
  318.     st    (a5,Flag_LhAPack-DT)
  319.     bra    Opt_Next
  320.  
  321. .Off:
  322.     addq.l    #3,a0
  323.     clr.b    (a5,Flag_LhAPack-DT)
  324.     bra    Opt_Next
  325.  
  326. Opt_PPackOut:
  327.     cmp.b    #"!",2(a0)
  328.     beq.b    .Off
  329.     tst.b    (a5,Flag_LhAPack-DT)
  330.     bne    Err_BadLogic
  331.     addq.l    #2,a0
  332.     st    (a5,Flag_CrunchBuf-DT)
  333.     tst.l    _PPBase
  334.     bne.b    Opt_Next
  335.     move.l    #Text_PowerPackNeed,d2
  336.     bra    ShowErr
  337.  
  338. .Off:
  339.     addq.l    #3,a0
  340.     clr.b    (a5,Flag_CrunchBuf-DT)
  341.     bra.b    Opt_Next
  342.  
  343. Opt_TabConv:
  344.     addq.l    #2,a0
  345.     cmp.b    #"!",(a0)
  346.     beq.b    .Off
  347.     tst.b    (a5,TabSize-DT)
  348.     bne    Err_BadLogic
  349.     cmp.b    #" ",(a0)
  350.     beq.b    Opt_TabConv1
  351.     move.l    a0,-(sp)
  352.     bsr    GetNum
  353.     move.l    (sp)+,a0
  354.     bsr    FindWhite
  355.     cmp.l    #16,d0
  356.     bhi    Err_BadComLine
  357.     cmp.l    #1,d0
  358.     bcs    Err_BadComLine
  359.     move.b    d0,(a5,TabSize-DT)
  360.     bra.b    Opt_Next
  361.  
  362. .Off:
  363.     addq.l    #1,a0
  364.     tst.b    (a5,SpaceSize-DT)    ; SpaceConv has TabConv always on, don't
  365.     bne    Opt_Next        ; turn that off.
  366.     clr.b    (a5,TabSize-DT)
  367.     bra    Opt_Next
  368.  
  369. Opt_TabConv1:
  370.     move.b    #8,(a5,TabSize-DT)
  371.     bra.b    Opt_Next
  372.  
  373. Opt_SpaceConv:
  374.     addq.l    #2,a0
  375.     cmp.b    #"!",(a0)
  376.     beq.b    .Off
  377.     tst.b    (a5,SpaceSize-DT)    ; If we have a old SpaceConv, new is ok.
  378.     bne.b    .Okay
  379.     tst.b    (a5,TabSize-DT)
  380.     bne    Err_BadLogic
  381.  
  382. .Okay:
  383.     tst.b    (a5,Size_MakeEOLs-DT)
  384.     bne    Err_BadLogic
  385.     cmp.b    #" ",(a0)
  386.     beq.b    .Default
  387.     move.l    a0,-(sp)
  388.     bsr    GetNum
  389.     move.l    (sp)+,a0
  390.     bsr    FindWhite
  391.     cmp.l    #16,d0
  392.     bhi    Err_BadComLine
  393.     cmp.l    #1,d0
  394.     bcs    Err_BadComLine
  395.     move.b    d0,(a5,SpaceSize-DT)
  396.     bra.b    Opt_Next
  397.  
  398. .Default:
  399.     move.b    #8,(a5,SpaceSize-DT)
  400.     move.b    #8,(a5,TabSize-DT)
  401.     bra    Opt_Next
  402.  
  403. .Off
  404.     addq.l    #1,a0
  405.     tst.b    (a5,SpaceSize-DT)
  406.     beq.b    Opt_Next
  407.     clr.b    (a5,SpaceSize-DT)
  408.     clr.b    (a5,TabSize-DT)
  409.     bra    Opt_Next
  410.  
  411. Opt_MakeEOLs:
  412.     cmp.b    #"!",2(a0)
  413.     beq    .Off
  414.     tst.b    (a5,SpaceSize-DT)
  415.     bne    Err_BadLogic
  416.     move.b    2(a0),d0
  417.     cmp.b    #" ",d0
  418.     beq.w    Err_BadComLine
  419.     sub.b    #"0",d0
  420.     cmp.b    #9,d0
  421.     bhi    Err_BadComLine
  422.     cmp.b    #1,d0
  423.     bcs    Err_BadComLine
  424.     move.b    3(a0),d1
  425.     cmp.b    #" ",d1
  426.     beq.b    Opt_MakeEOLs1
  427.     sub.b    #"0",d1
  428.     cmp.b    #9,d1
  429.     bhi    Err_BadComLine
  430.     cmp.b    #0,d1
  431.     bcs    Err_BadComLine
  432.     ext.w    d0
  433.     mulu    #10,d0
  434.     add.b    d1,d0
  435.     move.b    d0,(a5,Size_MakeEOLs-DT)
  436.     addq.l    #4,a0
  437.     bra.b    Opt_Next
  438.  
  439. .Off:
  440.     clr.b    (a5,Size_MakeEOLs-DT)
  441.     addq.l    #3,a0
  442.     bra.b    Opt_Next
  443.  
  444. Opt_MakeEOLs1:
  445.     move.b    d0,(a5,Size_MakeEOLs-DT)
  446.     addq.l    #3,a0
  447.     bra.b    Opt_Next
  448.  
  449. Opt_NoBufferMode:
  450.     addq.l    #2,a0
  451.     cmp.b    #"!",(a0)
  452.     beq.b    .Off
  453.     st    (a5,Mode_NoBuffer-DT)
  454.     bra    Opt_Next
  455.  
  456. .Off:
  457.     addq.l    #1,a0
  458.     clr.b    (a5,Mode_NoBuffer-DT)
  459.  
  460. Opt_Next:
  461.     cmp.b    #" ",(a0)
  462.     bne    Err_BadComLine
  463.     bsr    SkipSpace
  464.     cmp.l    #0,a0
  465.     beq.w    Err_BadComLine
  466.     bra.w    ParseStart
  467.  
  468. FromPCMode:
  469.     move.b    #MODE_FROMPC,(a5,Mode-DT)
  470.     move.l    #Table_FromPC,(a5,Table-DT)
  471.     bra.w    NameParse
  472.  
  473. FromSF7Mode:
  474.     move.b    #MODE_FROMSF7,(a5,Mode-DT)
  475.     move.l    #Table_FromSF7,(a5,Table-DT)
  476.     bra.w    NameParse
  477.  
  478. ToSF7Mode:
  479.     move.b    #MODE_TOSF7,(a5,Mode-DT)
  480.     move.l    #Table_ToSF7,(a5,Table-DT)
  481.     bra.w    NameParse
  482.  
  483. CombinedMode:
  484.     move.b    #MODE_COMBINED,(a5,Mode-DT)
  485.     move.l    #Table_Combined,(a5,Table-DT)
  486.     bra.w    NameParse
  487.  
  488. ToPCMode:
  489.     move.b    #MODE_TOPC,(a5,Mode-DT)
  490.     move.l    #Table_ToPC,(a5,Table-DT)
  491.     bra.w    NameParse
  492.  
  493. ToUpCaseMode:
  494.     move.b    #MODE_TOUPCASE,(a5,Mode-DT)
  495.     move.l    #Table_Uppercase,(a5,Table-DT)
  496.     bra.b    NameParse
  497.  
  498. ToLowCaseMode:
  499.     move.b    #MODE_TOLOWCASE,(a5,Mode-DT)
  500.     move.l    #Table_Lowercase,(a5,Table-DT)
  501.     bra.b    NameParse
  502.  
  503. ModeToNull:
  504.     move.b    #MODE_TONULL,(a5,Mode-DT)
  505.     move.l    #Table_Null,(a5,Table-DT)
  506.     bra.b    NameParse
  507.  
  508. ModeToOnlyASCII:
  509.     move.b    #MODE_TOASCII,(a5,Mode-DT)
  510.     move.l    #Table_Null,(a5,Table-DT)
  511.  
  512. NameParse:
  513.     addq.l    #1,a0            ; One after Mode
  514.     bsr    SkipSpace
  515.     cmp.l    #0,a0
  516.     beq.w    Err_BadComLine
  517.     move.l    a0,(a5,SourceNameStart-DT)
  518.     bsr    FindEnd
  519.     move.l    a0,(a5,SourceNameEnd-DT)
  520.     addq.l    #1,a0            ; Find the length for source name.
  521.     sub.l    (a5,SourceNameStart-DT),a0
  522.     move.l    a0,(a5,SourceNameLen-DT)
  523.  
  524.     move.l    (a5,SourceNameStart-DT),a0
  525.     lea    (a5,SourceName-DT),a1    ; Copy the name to SourceName
  526.     move.l    (a5,SourceNameLen-DT),d0
  527.     bsr    CopyName
  528.  
  529.     lea    (a5,SourceName-DT),a0
  530.     bsr    FormFileLinks
  531.     move.l    #FileLinkBase,(a5,CurrentLink-DT)
  532.     beq    LinkEnd
  533.  
  534. StartNewFile:
  535.     move.l    (a5,CurrentLink-DT),a0    ; Get the next FileLink.
  536.     move.l    (a0,fl_Next),a0
  537.     move.l    a0,(a5,CurrentLink-DT)
  538.     beq    LinkEnd
  539.  
  540.     clr.b    (a5,Flag_CrunchTried-DT)
  541.     move.l    (fl_Size,a0),(a5,SourceLen-DT)
  542.     lea    (fl_FileName,a0),a1
  543.     lea    (a5,RealSourceName-DT),a0
  544.     bsr    StrCpy
  545.  
  546.     move.l    (a5,SourceNameEnd-DT),a0
  547.     addq.l    #1,a0
  548.     tst.b    (a0)
  549.     beq.w    NoDest
  550.     bsr    SkipSpace
  551.     move.l    a0,(a5,DestNStart-DT)    ; If 0, go NoDest
  552.     beq.w    NoDest
  553.     bsr    FindEnd
  554.     addq.l    #1,a0            ; Add 1 to DestName end, and get
  555.     sub.l    (a5,DestNStart-DT),a0    ; DestNameLen in a0
  556.     move.l    a0,d0
  557.     move.l    (a5,DestNStart-DT),a0    ; Copy the destination name to DestName.
  558.     lea    (a5,DestName-DT),a1
  559.     bsr    CopyName
  560.  
  561.     move.l    #DestName,d1        ; Try to lock dest filename.
  562.     move.l    #ACCESS_READ,d2
  563.     Call    Dos,Lock
  564.     move.l    d0,(a5,DestLock-DT)
  565.     beq.w    DestNameCheck        ; If no lock, we'll have a file.
  566.  
  567.     move.l    (a5,DestLock-DT),d1    ; Otherwise check it
  568.     move.l    #FIB,d2
  569.     Call    Dos,Examine
  570.     move.l    d0,-(sp)        ; Save result code
  571.     move.l    (a5,DestLock-DT),d1
  572.     Call    Dos,UnLock
  573.     clr.l    (a5,DestLock-DT)
  574.     move.l    (sp)+,d0        ; Boolean
  575.     beq.w    Err_DestCorrupt        ; 0 means error
  576.     lea    FIB,a0
  577.     tst.l    fib_DirEntryType(a0)    ; Dir or a file?
  578.     bgt    DestIsDir        ; > 0 means directory.
  579.  
  580. DestNameCheck:
  581.     lea    MyAnchor,a0
  582.     btst.b    #APB_ITSWILD,(a0,ap_Flags)
  583.     bne    Err_FileDest
  584.     bra     OpenFiles
  585.  
  586. LinkEnd:
  587.     tst.b    (a5,Flag_FileFound-DT)
  588.     beq    Err_NoSource
  589.     st    (a5,Flag_Stop-DT)
  590.     bra    EndProgram
  591.  
  592. DestIsDir:
  593.     move.l    #DestName,d1        ; Add the source name to dest path.
  594.     move.l    #RealSourceName,d2
  595.     move.l    #256,d3
  596.     Call    Dos,AddPart
  597.     moveq    #3,d7
  598.     tst.l    d0
  599.     beq    CodeError
  600.     bra.b    OpenFiles
  601.  
  602. NoDest:
  603.     clr.b    Flag_DestName
  604.     move.l    (a5,CurrentLink-DT),a1
  605.     add.l    #fl_FullName,a1        ; If no destination name, use the
  606.     lea    (a5,DestName-DT),a0    ; sourcename (i.e. writing on the
  607.     bsr    StrCpy            ; original).
  608.     subq.l    #1,a0
  609.     move.l    a0,a1
  610.  
  611.     tst.b    (a5,Flag_LhAPack-DT)    ; Or if we are LhA packing the source.
  612.     bne.b    .NoSuffix
  613.     tst.b    (a5,Mode_NoBuffer-DT)    ; If we have a buffer, add no suffix.
  614.     bne.b    .AddSuffix
  615.  
  616. .NoSuffix:
  617.     st    (a5,Mode_SrcDeleted-DT)
  618.     bra.b    OpenFiles
  619.  
  620. .AddSuffix:
  621.     cmp.b    #MODE_TOPC,(a5,Mode-DT)    ; Add the right type of suffix.
  622.     beq.b    PCSuffix
  623.     cmp.b    #MODE_TOSF7,(a5,Mode-DT)
  624.     beq.b    SF7Suffix
  625.  
  626. AmigaSuffix:
  627.     lea    Text_AmigaSuf,a0
  628.     bra.b    AddSuffix
  629.  
  630. PCSuffix:
  631.     lea    Text_PCSuf,a0
  632.     bra.b    AddSuffix
  633.  
  634. SF7Suffix:
  635.     lea    Text_SF7Suf,a0
  636.  
  637. AddSuffix:
  638.     move.b    (a0)+,(a1)+
  639.     bne.b    AddSuffix
  640.  
  641. OpenFiles:
  642.     tst.b    (a5,Mode_NoBuffer-DT)    ; We have a buffer, go to OpenFilesBuf.
  643.     beq.w    OpenFilesBuf
  644.     bsr    AllocBuffers
  645.     bsr    OpenCheckPP
  646.     bsr    OpenDest
  647.     moveq    #0,d3
  648.     bra.w    ReadBlock
  649.  
  650. ; Open file CurrentLink.fl_FullName and check if it's PowerPacked.
  651. ; If we have PP library, decrunch the file.
  652. ; If not, show error.
  653.  
  654. OpenCheckPP:
  655.     move.l    (a5,CurrentLink-DT),a0
  656.     bsr    ClearPrintBuf        ; Start a new buffer.
  657.     move.l    #Text_ConvFile1,a0
  658.     bsr    AddPrintBuf
  659.     move.l    (a5,CurrentLink-DT),a0
  660.     lea    fl_FileName(a0),a0
  661.     bsr    AddPrintBuf
  662.     move.l    #Text_ConvFile2,a0
  663.     bsr    AddPrintBuf
  664.     bsr    WritePrintBuf
  665.  
  666.     move.l    (a5,CurrentLink-DT),d1
  667.     add.l    #fl_FullName,d1
  668.     move.l    #MODE_OLDFILE,d2
  669.     Call    Dos,Open
  670.     moveq    #1,d7            ; Unlikely error -code.
  671.     move.l    d0,(a5,SourceHandle-DT)
  672.     beq.w    CodeError
  673.  
  674.     bsr    PrintReading
  675.     move.l    (a5,SourceHandle-DT),d1    ; Read 4 bytes.
  676.     move.l    #TempBuf,d2
  677.     move.l    #4,d3
  678.     Call    Dos,Read
  679.     cmp.l    #4,d0            ; Did we read 4 bytes?
  680.     bne.b    .SeekBack        ; No, just seek back.
  681.     move.l    (a5,TempBuf-DT),d0    ; Get a long from the buffer, and check
  682.     cmp.l    #"PP20",d0        ; if it is a PowerPacker datafile.
  683.     beq.w    .PackedData
  684.     cmp.l    #"PX20",d0        ; if it is a PowerPacker datafile.
  685.     beq.w    .PackedData
  686.  
  687. .SeekBack:
  688.     move.l    (a5,SourceHandle-DT),d1    ; Seek back to the
  689.     moveq    #0,d2            ; beginning of the file.
  690.     moveq    #OFFSET_BEGINNING,d3
  691.     Call    Dos,Seek
  692.     bsr    MakeSourceASCII
  693.     rts
  694.  
  695. .PackedData:
  696.     move.l    (a5,SourceHandle-DT),d1
  697.     Call    Dos,Close
  698.     clr.l    (a5,SourceHandle-DT)
  699.  
  700.     move.l    _PPBase,a6
  701.     IFD    Code020
  702.     tst.l    a6
  703.     ENDC
  704.     IFND    Code020
  705.     cmp.l    #0,a6
  706.     ENDC
  707.     beq    Err_PowerPacked
  708.     tst.b    (a5,Mode_NoBuffer-DT)
  709.     bne    Err_NeedBufPP
  710.  
  711.     move.l    #Text_Decrunching,d2
  712.     bsr    PrintText
  713.  
  714.     st    (a5,Flag_PPUsed-DT)
  715.     move.l    (a5,CurrentLink-DT),a0
  716.     add.l    #fl_FullName,a0
  717.     moveq    #DECR_NONE,d0
  718.     moveq    #0,d1            ; Memory type.
  719.     lea    (a5,SourcePointer-DT),a1
  720.     lea    (a5,SourceLen-DT),a2
  721.     move.l    #0,a3            ; Use default PW function.
  722.     Call    PP,ppLoadData    
  723.     tst.l    d0
  724.     bne.b    .PackedError        ; If error.
  725.     bsr    MakeSourceASCII
  726.     rts
  727.  
  728. .PackedError:
  729.     cmp.l    #PP_OPENERR,d0        ; Should never happen, since we did
  730.     beq    Err_SourceCorrupt    ; check that it was a PP file.
  731.     cmp.l    #PP_READERR,d0
  732.     beq    Err_SourceCorrupt
  733.     cmp.l    #PP_NOMEMORY,d0
  734.     beq    Err_NoMem
  735.     cmp.l    #PP_PASSERR,d0
  736.     beq    Err_PassError
  737.     cmp.l    #PP_EMPTYFILE,d0
  738.     beq    Err_SourceCorrupt
  739.     cmp.l    #PP_UNKNOWNPP,d0
  740.     beq    Err_UnknownPP
  741.     moveq    #2,d7
  742.     bra    CodeError
  743.  
  744. OpenFilesBuf:
  745.     bsr    OpenCheckPP
  746.  
  747.     tst.b    (a5,Flag_PPUsed-DT)    ; If the file was loaded by PP, we
  748.     beq    OpenFilesNoPP        ; don't have to alloc memory or read.
  749.     move.l    (a5,SourceLen-DT),(a5,ReadBytes-DT)
  750.     bra    ReadFinished
  751.  
  752. OpenFilesNoPP:
  753.     move.l    (a5,SourceLen-DT),d0        ; Allocate for the whole source file.
  754.     moveq    #0,d1            ; No special needs for the memory.
  755.     Call    Exec,AllocMem
  756.     move.l    d0,(a5,SourcePointer-DT)
  757.     beq.w    Err_NoMem
  758.  
  759. ReadFile:
  760.     move.l    (a5,SourceHandle-DT),d1
  761.     move.l    (a5,SourcePointer-DT),d2
  762.     add.l    (a5,ReadBytes-DT),d2    ; To our file buffer.
  763.     move.l    RBlockSize,d3
  764.     clr.w    (a5,TickCount-DT)
  765.     Call    Dos,Read
  766.     cmp.l    #-1,d0
  767.     beq.w    Err_ReadFail        ; If error reading the file.
  768.     add.l    d0,(a5,ReadBytes-DT)
  769.     move.l    d0,-(sp)        ; Save "bytes read".
  770.  
  771.     bsr    CalcReadRate        ; Determine the optimal block size.
  772.  
  773.     bsr    ClearPrintBuf        ; Start a new buffer.
  774.  
  775.     move.l    #Text_Read,a0        ; Print our progress to Shell.
  776.     bsr    AddPrintBuf
  777.  
  778.     lea    (a5,ReadASCII-DT),a0    ; First convert the number into a
  779.     move.l    (a5,ReadBytes-DT),d0    ; string, and then add the string into
  780.     bsr    Num2ASCII        ; the buffer.
  781.  
  782.     bsr    AddPrintBuf
  783.  
  784.     move.l    #Text_Slash,a0
  785.     bsr    AddPrintBuf
  786.  
  787.     move.l    (a5,SourceLenASCIIAddr-DT),a0
  788.     bsr    AddPrintBuf
  789.  
  790.     move.l    #Text_CR,a0        ; And back to the beginning of the line.
  791.     bsr    AddPrintBuf
  792.     bsr    WritePrintBuf
  793.  
  794.     move.l    (a7)+,d0        ; How many bytes we read, if null, we're
  795.     beq.b    ReadFinished        ; finished.
  796.  
  797.     moveq    #0,d0            ; Get the signals.
  798.     moveq    #0,d1
  799.     Call    Exec,SetSignal
  800.  
  801.     btst    #SIGBREAKB_CTRL_C,d0    ; Check if ^C was pressed.
  802.     bne    BreakPressed
  803.  
  804.     bra.w    ReadFile        ; Read more of the file.
  805.  
  806. ReadFinished:
  807.     bsr    AllocBuffers
  808.     move.l    (a5,ReadBytes-DT),(a5,LeftBytes-DT)
  809.     tst.b    (a5,Flag_PPUsed-DT)
  810.     bne    ReadFinished2
  811.  
  812.     move.l    (a5,SourceHandle-DT),d1    ; Close the source, since we're done.
  813.     Call    Dos,Close
  814.     clr.l    (a5,SourceHandle-DT)    ; Note that it's closed.
  815.  
  816. ReadFinished2:
  817.     bsr    OpenDest
  818.     moveq    #0,d3
  819.     bra.w    MoreData
  820.  
  821. ReadBlock:
  822.     tst.b    (a5,Mode_NoBuffer-DT)
  823.     beq.b    MoreData        ; We have a buffer -> MoreData
  824.     movem.l    d0/d2-d7/a0-a6,-(sp)
  825.     bsr    PrintReading
  826.     move.l    (a5,SourceHandle-DT),d1    ; Otherwise read.
  827.     move.l    (a5,SourcePointer-DT),d2
  828.     move.l    (a5,Size_SrcBuf-DT),d3
  829.     Call    Dos,Read
  830.     cmp.l    #-1,d0
  831.     beq.w    Err_ReadFail        ; Couldn't read?  -> Err_ReadFail.
  832.     add.l    d0,(a5,ReadBytes-DT)
  833.     add.l    d0,(a5,InputBytes-DT)
  834.     move.l    d0,d1
  835.     beq.b    RB_CloseFiles        ; !ReadBytes -> Quit.
  836.     movem.l    (sp)+,d0/d2-d7/a0-a6
  837.     movem.l    d0/d2-d7/a0-a6,-(sp)
  838.     bsr    PrintStats
  839.     movem.l    (sp)+,d0/d2-d7/a0-a6
  840.     subq.l    #1,d1            ; Counter always one less than loops.
  841.     move.l    (a5,SourcePointer-DT),a0
  842.     bra.w    CheckOutBuf        ; Continue converting.
  843.  
  844. RB_CloseFiles:                ; Same as CloseFiles, but pops
  845.     movem.l    (sp)+,d0/d2-d7/a0-a6    ; the regs after ReadBlock messing with
  846.     bra.w    CloseFiles        ; them.
  847.  
  848. MoreData:
  849.     tst.l    (a5,LeftBytes-DT)    ; We have no more bytes left?
  850.     beq.w    CloseFiles        ; -> Quit.
  851.     move.l    (a5,LeftBytes-DT),d1
  852.     clr.l    (a5,LeftBytes-DT)
  853.     move.l    (a5,SourcePointer-DT),a0
  854.     add.l    (a5,InputBytes-DT),a0
  855.     add.l    d1,(a5,InputBytes-DT)
  856.     subq.l    #1,d1            ; Loop counter starts from 0, i.e. -1.
  857.     bra.w    CheckOutBuf
  858.  
  859. MoreCharacters:
  860.     move.b    (a0)+,d0        ; Get a new byte from the buffer.
  861.     and.w    #$ff,d0            ; a3 contains the table base-address.
  862.     move.l    d3,-(sp)
  863.     move.b    (a3,d0.w),d0        ; Replace the original character.
  864.     beq.b    NoChar            ; $00 - Trash this byte.
  865.  
  866.     tst.b    (a5,Flag_AStrip-DT)
  867.     beq.b    .NoAStrip
  868.     bsr    ANSIStrip
  869.     bra.b    NoChar
  870.  
  871. .NoAStrip:
  872.     tst.b    (a5,Flag_INStrip-DT)
  873.     beq.b    .NoINStrip
  874.     bsr    InterNetStrip
  875.     bra.b    NoChar
  876.  
  877. .NoINStrip:
  878.     bsr    WhiteProcess
  879.     tst.l    d0            ; Null = Insert nothing.
  880.     beq.b    NoChar
  881.     bsr    InsertInDest
  882.  
  883. NoChar:
  884.     move.l    (sp)+,d3
  885.     addq.l    #1,d3            ; Total bytes converted.
  886.     subq.l    #1,d1            ; One less byte in the read buffer.
  887.     bmi    ReadBlock        ; Went negative, load more.
  888.  
  889. CheckOutBuf:
  890.     tst.b    (a5,Flag_StatsDue-DT)    ; Check if we should show the stats.
  891.     bne.b    .DoStats
  892.  
  893. .ContCheckOutBuf:
  894.     move.l    (a5,Size_DstBuf-DT),d0
  895.     sub.l    #SIZE_MAXNEW,d0
  896.     cmp.l    d0,d2            ; Have we converted a full buffer yet?
  897.     bls.b    MoreCharacters        ; Everything okay, continue conversion.
  898.     bra.b    WriteDestBuf
  899.  
  900. .DoStats:
  901.     bsr    PrintStats
  902.     bra.b    .ContCheckOutBuf
  903.  
  904. WriteDestBuf:
  905.     movem.l    d1/d3-d7/a0/a2-a5,-(sp)
  906.     move.l    d3,-(sp)
  907.     bsr    PrintWriting
  908.     move.l    (a5,DestHandle-DT),d1    ; Write the converted data.
  909.     move.l    d2,d3            ; Number of bytes to write.
  910.     add.l    d2,(a5,WrittenBytes-DT)    ; Add the buffer to WrittenBytes.
  911.     move.l    (a5,DestPointer-DT),d2
  912.     Call    Dos,Write
  913.     cmp.l    #-1,d0
  914.     beq.w    Err_WriteFail
  915.     tst.b    (a5,Mode_SrcDeleted-DT)    ; If the sourcefile has been destroyed,
  916.     bne.b    .NoBreak        ; don't allow breaking.
  917.     move.l    (sp)+,d3
  918.     bsr    PrintStats
  919.     moveq    #0,d0            ; Get the signals.
  920.     moveq    #0,d1
  921.     Call    Exec,SetSignal
  922.     btst    #SIGBREAKB_CTRL_C,d0    ; Check if ^C was pressed
  923.     bne.w    BreakPressed
  924.  
  925. .NoBreak:
  926.     movem.l    (sp)+,d1/d3-d7/a0/a2-a5
  927.     moveq    #0,d2            ; No converted bytes now.
  928.     move.l    (a5,DestPointer-DT),a1
  929.     bra.w    MoreCharacters
  930.  
  931. CloseFiles:
  932.     tst.l    (a5,EOLs-DT)
  933.     beq    .NoEOLsLeft
  934.     addq.l    #1,d2
  935.     bsr    InsertSingleEOL
  936.     tst.b    (a5,Mode-DT)        ; If ToPC or ToSF7, add a CR too.
  937.     bpl    .NoEOLsLeft
  938.     addq.l    #1,d2
  939.  
  940. .NoEOLsLeft:
  941.     bsr    PrintWriting
  942.     move.l    d2,d3            ; Do we have stuff in DestBuf?
  943.     beq.b    CF_TellData        ; No, show the final stats.
  944.     move.l    (a5,DestHandle-DT),d1    ; We do, flush it.
  945.     add.l    d2,(a5,WrittenBytes-DT)    ; Add the buffer to WrittenBytes.
  946.     move.l    (a5,DestPointer-DT),d2
  947.     Call    Dos,Write
  948.     cmp.l    #-1,d0
  949.     beq.w    Err_WriteFail
  950.  
  951. CF_TellData:
  952.     bsr    ClearPrintBuf        ; Tell the file size change.
  953.     move.l    #Text_Final,a0
  954.     bsr    AddPrintBuf
  955.  
  956.     move.l    (a5,WrittenBytes-DT),d0
  957.  
  958.     sub.l    (a5,ReadBytes-DT),d0
  959.     bmi    CloseFiles1        ; Negative
  960.  
  961.     move.l    d0,d7
  962.     beq.b    CloseFiles2        ; If zero, no sign.
  963.  
  964.     move.l    #Text_PosSign,a0
  965.     bsr    AddPrintBuf
  966.  
  967.     bra.b    CloseFiles2
  968.  
  969. CloseFiles1:
  970.     neg.l    d0
  971.     move.l    #Text_NegSign,a0
  972.     bsr    AddPrintBuf
  973.  
  974. CloseFiles2:
  975.     lea    (a5,NumberBuf-DT),a0    ; Print the final statistics.
  976.     bsr    Num2ASCII
  977.     bsr    AddPrintBuf
  978.  
  979.     move.l    #Text_DoubleSpace,a0
  980.     bsr    AddPrintBuf
  981.  
  982.     move.l    (a5,WrittenBytes-DT),d0    ; File size change as a percentage.
  983.     move.l    (a5,ReadBytes-DT),d1
  984.     bsr    Percentage
  985.  
  986.     lea    (a5,NumberBuf-DT),a0
  987.     bsr    Num2ASCII
  988.  
  989.     bsr    AddPrintBuf
  990.  
  991.     move.l    #Text_PercentSign,a0
  992.     bsr    AddPrintBuf
  993.  
  994.     move.l    #Text_LF,a0
  995.     bsr    AddPrintBuf
  996.     tst.b    (a5,Flag_CrunchBuf-DT)
  997.     bne    .OnlyOneLF
  998.     move.l    #Text_LF,a0
  999.     bsr    AddPrintBuf
  1000.  
  1001. .OnlyOneLF:
  1002.     bsr    WritePrintBuf
  1003.     bra.w    EndProgram
  1004.  
  1005. HelpText:
  1006.     st    (a5,Flag_Stop-DT)    ; We don't want to continue after
  1007.     move.l    #Text_HelpText,d2    ; printing the help text.
  1008.     bsr    PrintText
  1009.     bra.w    EndProgram
  1010.  
  1011. Credits:
  1012.     st    (a5,Flag_Stop-DT)    ; Neither after credits.
  1013.     move.l    #Text_Credits,d2
  1014.     bsr    PrintText
  1015.     bra.w    EndProgram
  1016.  
  1017. ********************
  1018. ** ERROR ROUTINES **
  1019. ********************
  1020.  
  1021. CodeError:
  1022.     st    (a5,Flag_Stop-DT)    ; Tell a serious error has occured,
  1023.     move.l    d7,-(sp)        ; and a special error code in D7.
  1024.     move.l    #Text_CodeError,d2
  1025.     bsr    PrintText
  1026.     lea    (a5,NumberBuf-DT),a0
  1027.     move.l    (sp)+,d0
  1028.     bsr    Num2ASCII
  1029.     move.l    a0,d2
  1030.     move.l    d0,d3
  1031.     bsr    PrintTextLen
  1032.     move.l    #Text_LF,d2
  1033.     bsr    PrintText
  1034.     bra.w    EndProgram
  1035.  
  1036. Err_CrunchReadWrite:
  1037.     move.l    #Text_CrunchReadWrite,d2
  1038.     bra    ShowWarn
  1039.  
  1040. Err_CrunchOverflow:
  1041.     move.l    #Text_CrunchOverflow,d2
  1042.     bra    ShowWarn
  1043.  
  1044. Err_NoCrunchMem:
  1045.     move.l    #Text_NoCrunchMem,d2
  1046.     bra    ShowWarn
  1047.  
  1048. Err_NoCrunchFile:
  1049.     move.l    #Text_NoCrunchFile,d2
  1050.     bra    ShowWarn
  1051.  
  1052. Err_NeedBufPP:
  1053.     move.l    #Text_NeedBufPP,d2
  1054.     bra    ShowErr
  1055.  
  1056. Err_UnknownPP:
  1057.     move.l    #Text_UnknownPP,d2
  1058.     bra    ShowErr
  1059.  
  1060. Err_PassError:
  1061.     move.l    #Text_WrongPass,d2
  1062.     bra    ShowErr
  1063.  
  1064. Err_FileDest:
  1065.     move.l    #Text_FileDest,d2
  1066.     bra    ShowErr
  1067.  
  1068.     IFD    Code020
  1069.  
  1070. Err_OldProcessor:
  1071.     move.l    #Text_OldProcessor,d2
  1072.     bra    ShowErr
  1073.  
  1074.     ENDC
  1075.  
  1076. Err_NewerKickNeeded:
  1077.     move.l    #Text_NewKickNeed,d2
  1078.     bra    ShowErr
  1079.  
  1080. Err_NoSource:
  1081.     move.l    #Text_NoSource,d2
  1082.     bra.b    ShowErr
  1083.  
  1084. Err_BadComLine:
  1085.     move.l    #Text_BadComLine,d2
  1086.     bra.b    ShowErr
  1087.  
  1088. Err_NoDest:
  1089.     move.l    #Text_NoDest,d2
  1090.     bra.b    ShowErr
  1091.  
  1092. Err_NoComLineSpace:
  1093.     move.l    #Text_NoComLineSpace,d2
  1094.     bra.b    ShowErr
  1095.  
  1096. Err_BadLogic:
  1097.     move.l    #Text_BadLogic,d2
  1098.     bra.b    ShowErr
  1099.  
  1100. Err_NoMem:
  1101.     move.l    #Text_NoMemory,d2
  1102.     bra.b    ShowErr
  1103.  
  1104. Err_PowerPacked:
  1105.     move.l    #Text_PowerPacked,d2
  1106.     bra.b    ShowErr
  1107.  
  1108. Err_ReadFail:
  1109. Err_SourceCorrupt:
  1110.     move.l    #Text_BadSource,d2
  1111.     bra.b    ShowErr
  1112.  
  1113. Err_DestCorrupt:
  1114.     move.l    #Text_BadDest,d2
  1115.     bra.b    ShowErr
  1116.  
  1117. Err_SourceIsDir:
  1118.     move.l    #Text_SourceIsDir,d2
  1119.     bra.b    ShowErr
  1120.  
  1121. Err_WriteFail:
  1122.     move.l    #Text_WriteFail,d2
  1123.     bra.b    ShowErr
  1124.  
  1125. BreakPressed:
  1126.     st    (a5,Flag_Stop-DT)
  1127.     move.l    #Text_Break,d2
  1128.     bsr    PrintText
  1129.     bra.b    EndProgramErr
  1130.  
  1131. ShowWarn:                ; Show a non-fatal error.
  1132.     move.l    d2,-(sp)
  1133.     bsr    ClearPrintBuf
  1134.     lea    Text_Warning,a0
  1135.     bsr    AddPrintBuf
  1136.     move.l    (sp)+,a0
  1137.     bsr    AddPrintBuf
  1138.     lea    Text_ClearEOL,a0
  1139.     bsr    AddPrintBuf
  1140.     lea    Text_LF,a0
  1141.     bsr    AddPrintBuf
  1142.     bsr    WritePrintBuf
  1143.     bra.b    EndProgram
  1144.  
  1145. ShowErr:
  1146.     move.l    d2,-(sp)
  1147.     bsr    ClearPrintBuf
  1148.     lea    Text_Error,a0
  1149.     bsr    AddPrintBuf
  1150.     move.l    (sp)+,a0
  1151.     bsr    AddPrintBuf
  1152.     lea    Text_ClearEOL,a0
  1153.     bsr    AddPrintBuf
  1154.     lea    Text_LF,a0
  1155.     bsr    AddPrintBuf
  1156.     bsr    WritePrintBuf
  1157.     bra.b    EndProgramErr
  1158.  
  1159. EndProgram:
  1160.     clr.b    (a5,Mode_DeleteErrDest-DT)
  1161.     bra    EndProgramNoErr
  1162.  
  1163. EndProgramErr:
  1164.     move.l    #20,(a5,ErrorCode-DT)
  1165.     st    (a5,Flag_Stop-DT)
  1166.  
  1167. EndProgramNoErr:
  1168.     move.l    (a5,SourceHandle-DT),d1
  1169.     beq.b    EndProgram1
  1170.     Call    Dos,Close
  1171.     clr.l    (a5,SourceHandle-DT)
  1172.  
  1173. EndProgram1:
  1174.     move.l    (a5,DestHandle-DT),d1
  1175.     beq.b    EndProgram2
  1176.     Call    Dos,Close
  1177.     clr.l    (a5,DestHandle-DT)
  1178.  
  1179. EndProgram2:
  1180.     move.l    (a5,SourceLock-DT),d1
  1181.     beq.b    EndProgram3
  1182.     Call    Dos,UnLock
  1183.     clr.l    (a5,SourceLock-DT)
  1184.  
  1185. EndProgram3:
  1186.     move.l    (a5,DestLock-DT),d1
  1187.     beq.b    EndProgram4
  1188.     Call    Dos,UnLock
  1189.     clr.l    (a5,DestLock-DT)
  1190.  
  1191. EndProgram4:
  1192.     tst.b    (a5,Mode_DeleteErrDest-DT)
  1193.     beq.b    EndProgram5
  1194.     bsr    ClearPrintBuf
  1195.     lea    Text_Quote,a0
  1196.     bsr    AddPrintBuf
  1197.     lea    (a5,DestName-DT),a0
  1198.     bsr    AddPrintBuf
  1199.     lea    Text_Deleted,a0
  1200.     bsr    AddPrintBuf
  1201.     bsr    WritePrintBuf
  1202.     move.l    #DestName,d1
  1203.     Call    Dos,DeleteFile
  1204.  
  1205. EndProgram5:
  1206.     move.l    (a5,BigBufPtr-DT),a1
  1207.     IFD    Code020
  1208.     tst.l    a1
  1209.     ENDC
  1210.     IFND    Code020
  1211.     cmp.l    #0,a1
  1212.     ENDC
  1213.     beq.b    EndProgram6
  1214.     move.l    (a5,BigBufSize-DT),d0
  1215.     Call    Exec,FreeMem
  1216.     clr.l    (a5,BigBufPtr-DT)
  1217.     bra    EndProgram6
  1218.  
  1219. EndProgram6:
  1220.     tst.b    (a5,Mode_NoBuffer-DT)
  1221.     bne.b    EndProgram7
  1222.     move.l    (a5,SourcePointer-DT),a1
  1223.     IFD    Code020
  1224.     tst.l    a1
  1225.     ENDC
  1226.     IFND    Code020
  1227.     cmp.l    #0,a1
  1228.     ENDC
  1229.     beq.b    EndProgram7
  1230.     move.l    (a5,SourceLen-DT),d0
  1231.     Call    Exec,FreeMem
  1232.     clr.l    (a5,SourcePointer-DT)
  1233.  
  1234. EndProgram7:
  1235.  
  1236. EndProgram8:
  1237.     move.l    (a5,CrBuf-DT),a1
  1238.     IFD    Code020
  1239.     tst.l    a1
  1240.     ENDC
  1241.     IFND    Code020
  1242.     cmp.l    #0,a1
  1243.     ENDC
  1244.     beq    EndProgram9
  1245.     move.l    (a5,CrBuf-DT),a1
  1246.     move.l    (a5,CrSize-DT),d0
  1247.     Call    Exec,FreeMem
  1248.     clr.l    (a5,CrBuf-DT)
  1249.  
  1250. EndProgram9:
  1251.     move.l    (a5,CrFile-DT),d1
  1252.     beq    EndProgram10
  1253.     Call    Dos,Close
  1254.     clr.l    (a5,CrFile-DT)
  1255.  
  1256. EndProgram10:
  1257.     move.l    (a5,CrCrunchInfo-DT),a0
  1258.     IFD    Code020
  1259.     tst.l    a0
  1260.     ENDC
  1261.     IFND    Code020
  1262.     cmp.l    #0,a0
  1263.     ENDC
  1264.     beq    EndProgram11
  1265.     Call    PP,ppFreeCrunchInfo
  1266.     clr.l    (a5,CrCrunchInfo-DT)
  1267.  
  1268. EndProgram11:
  1269.     tst.b    (a5,Flag_Stop-DT)
  1270.     bne.b    EndProgram12
  1271.     tst.b    (a5,Flag_CrunchBuf-DT)
  1272.     bne.b    .Cont
  1273.     tst.b    (a5,Flag_LhAPack-DT)
  1274.     bne.b    .Cont
  1275.     bra.b    EndProgram12
  1276.  
  1277. .Cont:
  1278.     tst.b    (a5,Flag_CrunchTried-DT)
  1279.     bne.b    EndProgram12
  1280.     bsr    CrunchDestFile
  1281.  
  1282. EndProgram12:
  1283.     lea    (a5,CrunchSrcName-DT),a0
  1284.     tst.b    (a0)
  1285.     beq.b    EndProgram13
  1286.     move.l    a0,d1
  1287.     Call    Dos,DeleteFile
  1288.     lea    (a5,CrunchSrcName-DT),a0
  1289.     clr.b    (a0)
  1290.  
  1291. EndProgram13:
  1292.     tst.b    Flag_DestName        ; We had a destination, continue.
  1293.     bne.b    EndProgram14
  1294.     tst.b    (a5,Flag_LhAPack-DT)    ; The file wasn't LhA'ed.
  1295.     beq.b    EndProgram14
  1296.     tst.b    (a5,Flag_DidLhAPack-DT)
  1297.     beq.b    EndProgram14
  1298.     move.l    #SourceName,d1        ; LhA & No destination = Delete source.
  1299.     Call    Dos,DeleteFile
  1300.  
  1301. EndProgram14:
  1302.     tst.b    (a5,Flag_Stop-DT)
  1303.     bne    EndProgram15
  1304.     bsr    ClearVars
  1305.     bra    StartNewFile
  1306.  
  1307. EndProgram15:
  1308.     tst.b    (a5,Flag_AnchorUsed-DT)
  1309.     beq    EndProgram16
  1310.     move.l    #MyAnchor,d1
  1311.     Call    Dos,MatchEnd
  1312.  
  1313. EndProgram16:
  1314.     move.l    _PPBase,a1
  1315.     IFD    Code020
  1316.     tst.l    a1
  1317.     ENDC
  1318.     IFND    Code020
  1319.     cmp.l    #0,a1
  1320.     ENDC
  1321.     beq    EndProgram17
  1322.     Call    Exec,CloseLibrary
  1323.  
  1324. EndProgram17:
  1325.     tst.b    (a5,Flag_IntActive-DT)
  1326.     beq.b    EndProgram18
  1327.     moveq    #INTB_VERTB,d0        ; Remove the counter interrupt.
  1328.     lea    VertBInterrupt,a1
  1329.     Call    Exec,RemIntServer
  1330.  
  1331. EndProgram18:
  1332.     move.l    (a5,FileLinkBase-DT),a2
  1333.     cmp.l    #0,a2
  1334.     beq.b    EndProgramFinal
  1335.  
  1336. .ContFree:
  1337.     move.l    a2,a1
  1338.     move.l    (a2,fl_Next),a2        ; Get the link after this one.
  1339.     move.l    #fl_SIZEOF,d0
  1340.     Call    Exec,FreeMem
  1341.     cmp.l    #0,a2
  1342.     bne.b    .ContFree
  1343.  
  1344. EndProgramFinal:
  1345.     move.l    #Text_CursorOn,d2
  1346.     bsr    PrintText
  1347.     move.l    _DosBase,a1
  1348.     Call    Exec,CloseLibrary
  1349.     move.l    OldStack,sp        ; At least it's ok this way...
  1350.     move.l    (a5,ErrorCode-DT),d0
  1351.     rts
  1352.  
  1353. *********************
  1354. ** VERTB INTERRUPT **
  1355. *********************
  1356.  
  1357. ; On a 14.3MHz CPU the interrupt code takes .03% of the total cycles/sec.
  1358. ; Without the code, we could convert 13 more bytes/sec, as the conversion
  1359. ; rate is currently 50kB/sec.
  1360.  
  1361. VertBIntCode:
  1362.     addq.b    #1,(a1)            ; Add the frame counter.              12
  1363.     addq.w    #1,4(a1)        ; Add the tick counter.               16
  1364.     move.b    1(a1),d0        ; Get TickDelay.                  12
  1365.     cmp.b    (a1),d0            ; One second passed?                   8
  1366.     bls.b    .StuffDue        ;                                   10/8
  1367.     moveq    #0,d0            ;                                      4
  1368.     rts                ;                                     16
  1369.  
  1370. .StuffDue:
  1371.     clr.b    (a1)            ; Reset counter.                      12
  1372.     st    2(a1)            ; Set statistics due flag.            16
  1373.     moveq    #0,d0            ;                                      4
  1374.     rts                ;                                     16
  1375.  
  1376. **********
  1377. ** SUBS **
  1378. **********
  1379.  
  1380. ANSIStrip:
  1381.     cmp.b    #ANSI_WAIT,(a5,Flag_ANSIState-DT)
  1382.     beq    .Wait
  1383.     bcs    .Clear
  1384.     bhi    .Code
  1385.     IFD    Debug            ; ANSIState should always be one of the
  1386.     move.w    #$f00,$dff180        ; above.
  1387.     rts
  1388.     ENDC
  1389.  
  1390. .Wait:
  1391.     cmp.b    #"[",d0            ; We have found $1B, now there should be
  1392.     beq    .On            ; a "[" for a CSI.
  1393.     move.b    #ANSI_CLEAR,(a5,Flag_ANSIState-DT)
  1394.     move.l    d0,-(sp)
  1395.     move.l    #$1b,d0            ; Otherwise clear the buffered chars,
  1396.     bsr    InsertANSIOn        ; and back to ANSI_CLEAR state.
  1397.     move.l    (sp)+,d0
  1398.     bsr    InsertANSIOn
  1399.     rts
  1400.  
  1401. .On:
  1402.     move.b    #ANSI_CODE,(a5,Flag_ANSIState-DT)
  1403.     rts                ; Chars will be skipped until an alpha.
  1404.  
  1405. .Code:
  1406.     cmp.b    #"A",d0            ; An ANSI code ends in a alpha char,
  1407.     bcc    .Check1            ; check if we have such now.
  1408.     bra.b    .Check2
  1409.  
  1410. .Check1:
  1411.     cmp.b    #"Z",d0
  1412.     bls    .Off
  1413.  
  1414. .Check2:
  1415.     cmp.b    #"a",d0
  1416.     bcc    .Check3
  1417.     rts
  1418.  
  1419. .Check3:
  1420.     cmp.b    #"z",d0
  1421.     bls    .Off
  1422.     rts
  1423.  
  1424. .Off:
  1425.     move.b    #ANSI_CLEAR,(a5,Flag_ANSIState-DT)
  1426.     rts                ; Found the end of the ANSI code.
  1427.  
  1428. .Clear:
  1429.     cmp.b    #$1b,d0            ; A possible CSI start.
  1430.     beq.b    .GoWait
  1431.     cmp.b    #$9b,d0            ; A CSI.
  1432.     beq.b    .On
  1433.     bsr    InsertANSIOn        ; Otherwise just insert the new char.
  1434.     rts
  1435.  
  1436. .GoWait:
  1437.     move.b    #ANSI_WAIT,(a5,Flag_ANSIState-DT)
  1438.     rts                ; Expecting a "[" next, for a CSI.
  1439.  
  1440. InsertANSIOn:
  1441.     tst.b    (a5,Flag_INStrip-DT)    ; If InterNet strip is on, pass the
  1442.     beq.b    .NoINStrip        ; char to that routine.
  1443.     bsr    InterNetStrip
  1444.     rts
  1445.  
  1446. .NoINStrip:
  1447.     bsr    WhiteProcess        ; Otherwise send it to WhiteProcess().
  1448.     tst.l    d0            ; Null = Insert nothing.
  1449.     bne.b    .Insert            ; Otherwise insert it to the write buf.
  1450.     rts
  1451.  
  1452. .Insert:
  1453.     bsr    InsertInDest
  1454.     rts    
  1455.  
  1456. InsertInDest:
  1457.     move.b    d0,(a1)+        ; Store the translated byte in the buf.
  1458.     addq.l    #1,d2            ; Add the bytes to be saved.
  1459.     addq.w    #1,(a5,Col-DT)        ; And add the column counter.
  1460.     rts
  1461.  
  1462. InterNetStrip:
  1463.     move.b    d0,(a4)+        ; Insert the byte.
  1464.     addq.w    #1,(a5,INBufSize-DT)    ; If it was an EOL, we have a full line.
  1465.     cmp.b    #LF,d0            ; Now check the new line.
  1466.     beq.b    .FullLine
  1467.     cmp.b    #CR,d0
  1468.     beq.b    .FullLine
  1469.     rts
  1470.  
  1471. .FullLine:
  1472.     SaveR
  1473.     move.w    (a5,INBufSize-DT),d0    ; Insert a null in the end of buffer.
  1474.     lea    (a5,InterNetBuf-DT),a4
  1475.     clr.b    (a4,d0.w)
  1476.     tst.b    (a5,Flag_INStripActive-DT) ; If strip is not active, check if it
  1477.     beq.b    .TestInterNet        ; should be made active.
  1478.     clr.w    (a5,INBufSize-DT)    ; Otherwise kill this line, and check
  1479.     cmp.b    #LF,(a4)        ; if stripping should continue.
  1480.     beq.b    .CutOff
  1481.     cmp.b    #CR,(a4)        ; If the line only has an EOL, it's the
  1482.     beq.b    .CutOff            ; end of the header.
  1483.     LoadR
  1484.     lea    (a5,InterNetBuf-DT),a4    ; Reset the buffer ptr.
  1485.     rts
  1486.  
  1487. .CutOff:
  1488.     clr.b    (a5,Flag_INStripActive-DT) ; Last line of the header encountered.
  1489.     cmp.b    #1,(a5,Flag_INStrip-DT)    ; If the flag is 1, insert a note to the
  1490.     beq    .InsertInfo        ; file, otherwise insert nothing.
  1491.     LoadR
  1492.     bsr    ResetArea        ; Clear any stuff WhiteProcess has
  1493.     lea    (a5,InterNetBuf-DT),a4    ; buffered, and reset our own buffer.
  1494.     rts
  1495.  
  1496. .InsertInfo:
  1497.     lea    (a5,InterNetBuf-DT),a0    ; Insert a "HEADER REMOVED" text.
  1498.     lea    Text_INRemoved,a1
  1499.     bsr    StrCpy
  1500.     move.w    #81,(a5,INBufSize-DT)
  1501.     LoadR
  1502.     bsr    ResetArea
  1503.     lea    (a5,InterNetBuf-DT),a4
  1504.     add.l    #81,a4
  1505.     rts
  1506.  
  1507. .TestInterNet:
  1508. ;    move.l    a4,a0            ; Check if there's a period in the line.
  1509. ;    moveq    #".",d0
  1510. ;    bsr    StrChr
  1511. ;    tst.l    d0
  1512. ;    bne.b    .Cont            ; If so, a possible header line.
  1513. ;    bra.b    .FeedLine        ; If not, just feed the line on.
  1514.  
  1515. .Cont:
  1516. ;    move.l    a4,a0            ; Check for an exclamation mark, if
  1517. ;    moveq    #"!",d0            ; found this could be a header start.
  1518. ;    bsr    StrChr
  1519. ;    tst.l    d0
  1520. ;    bne.b    .Cont1
  1521. ;    bra.b    .FeedLine        ; Otherwise just feed the line.
  1522.  
  1523. .Cont1:
  1524.     move.l    a4,a0            ; Check if the line starts "From ".
  1525.     lea    Text_INFrom,a1
  1526.     moveq    #5,d0
  1527.     bsr    StrNCmp
  1528.     tst.l    d0
  1529.     beq.b    .PossibFrom
  1530.     move.l    a4,a0            ; Check if the line starts "Path: ".
  1531.     lea    Text_INPath,a1
  1532.     moveq    #6,d0
  1533.     bsr    StrNCmp
  1534.     tst.l    d0
  1535.     beq.b    .CutOn
  1536.     bra.b    .FeedLine        ; Otherwise it's not a header start.
  1537.  
  1538. .PossibFrom:
  1539.     move.l    a4,a0            ; If "From ", must also have a date and
  1540.     bsr    StrFirstNum        ; time, which means numbers.
  1541.     tst.l    d0
  1542.     bne.b    .CheckNext        ; Found, turn on the cut.
  1543.     bra.b    .FeedLine
  1544.  
  1545. .CheckNext:
  1546.     move.l    a4,a0            ; Check if there's a colon (in time).
  1547.     moveq    #":",d0
  1548.     bsr    StrChr
  1549.     tst.l    d0
  1550.     bne.b    .CutOn            ; If so, a possible header line.
  1551.  
  1552. .FeedLine:
  1553.     LoadR
  1554.     move.w    (a5,INBufSize-DT),d7
  1555.     subq.w    #1,d7
  1556.     lea    (a5,InterNetBuf-DT),a4
  1557.  
  1558. .FeedByte:
  1559.     addq.l    #1,d3            ; Total bytes converted.
  1560.     move.b    (a4)+,d0
  1561.     bsr    WhiteProcess
  1562.     tst.l    d0            ; Null = Insert nothing.
  1563.     beq.b    .NoInsert
  1564.     bsr    InsertInDest        ; Insert all the bytes we have buffered
  1565.                     ; to the write buffer.
  1566. .NoInsert
  1567.     dbf.b    d7,.FeedByte
  1568.     lea    (a5,InterNetBuf-DT),a4
  1569.     clr.w    (a5,INBufSize-DT)
  1570.     rts
  1571.  
  1572. .CutOn:
  1573.     clr.w    (a5,INBufSize-DT)
  1574.     st    (a5,Flag_INStripActive-DT)
  1575.     LoadR
  1576.     lea    (a5,InterNetBuf-DT),a4
  1577.     rts
  1578.  
  1579. WhiteProcess:
  1580.     cmp.b    #" ",d0            ; Process white.
  1581.     beq.b    FoundSpace
  1582.     bhi.b    FoundBlack
  1583.     cmp.b    #TAB,d0
  1584.     beq.b    FoundTab
  1585.     cmp.b    #LF,d0
  1586.     beq.b    FoundLF
  1587.     bra.b    FoundBlack
  1588.  
  1589. FoundSpace:
  1590.     tst.b    (a5,TabSize-DT)        ; Test for Tab-Space conversion.
  1591.     beq.b    .NoSpaceTab
  1592.     addq.l    #1,(a5,SpaceNumber-DT)
  1593.     addq.w    #1,(a5,Col-DT)
  1594.     tst.b    (a5,SpaceSize-DT)
  1595.     bne.b    .SpaceConv
  1596.     moveq    #0,d0            ; Insert nothing in write buffer.
  1597.     rts
  1598.  
  1599. .SpaceConv:
  1600.     bsr    SpaceConv
  1601.     moveq    #0,d0            ; Insert nothing in write buffer.
  1602.     rts
  1603.  
  1604. .NoSpaceTab:
  1605.     bsr    BufChar
  1606.     moveq    #0,d0            ; Insert nothing in write buffer.
  1607.     rts    
  1608.  
  1609. FoundTab:
  1610.     tst.b    (a5,TabSize-DT)        ; Test for Tab-Space conversion.
  1611.     beq    .NoSpaceTab
  1612.     bsr    TabConv
  1613.     tst.b    (a5,SpaceSize-DT)
  1614.     bne    .SpaceConv
  1615.     moveq    #0,d0            ; Insert nothing in write buffer.
  1616.     rts
  1617.  
  1618. .SpaceConv:
  1619.     bsr    SpaceConv
  1620.     moveq    #0,d0            ; Insert nothing in write buffer.
  1621.     rts
  1622.  
  1623. .NoSpaceTab:
  1624.     bsr    BufChar
  1625.     moveq    #0,d0            ; Insert nothing in write buffer.
  1626.     rts
  1627.  
  1628. FoundLF:
  1629.     clr.w    (a5,Col-DT)
  1630.     tst.b    (a5,Mode_NoCutSpace-DT)
  1631.     bne.b    .NoEndSpaceRem
  1632.     addq.l    #1,(a5,EOLs-DT)
  1633.     bsr    ResetArea
  1634.     moveq    #0,d0            ; Insert nothing in write buffer.
  1635.     rts
  1636.  
  1637. .NoEndSpaceRem:
  1638.     bsr    FlushArea
  1639.     bsr    InsertOneEOL    
  1640.     moveq    #0,d0            ; Insert nothing in write buffer.
  1641.     rts
  1642.  
  1643. FoundBlack:
  1644.     bsr    InsertEOLs        ; Insert all buffered EOLs.
  1645.     move.b    (a5,Size_MakeEOLs-DT),d3
  1646.     beq    .NoMakeEOLs        ; If MakeEOLs is on, convert all the
  1647.     BToLong    d3            ; buffered area to a single EOL.
  1648.     cmp.l    (a5,SpaceNumber-DT),d3
  1649.     bhi    .NoMakeEOLs
  1650.     bsr    ResetArea
  1651.     bsr    InsertSingleEOL
  1652.     addq.l    #1,d2
  1653.     rts
  1654.  
  1655. .NoMakeEOLs:                ; MakeEOLs is off, write all area to
  1656.     bsr    FlushArea        ; the buffer.
  1657.     rts
  1658.  
  1659. ; Gets the number starting at A0, and ending in ~[0-9]. Returns the number in
  1660. ; D0.
  1661.  
  1662. GetNum:
  1663.     lea    (a5,NumberBuf-DT),a1
  1664.  
  1665. .Loop:
  1666.     cmp.b    #"0",(a0)
  1667.     bcc.b    .CheckLow
  1668.     bra.b    .End
  1669.  
  1670. .CheckLow:
  1671.     cmp.b    #"9",(a0)
  1672.     bls.b    .Copy
  1673.     bra.b    .End
  1674.  
  1675. .Copy:
  1676.     move.b    (a0)+,(a1)+
  1677.     bra.b    .Loop
  1678.  
  1679. .End:
  1680.     clr.b    (a1)
  1681.     lea    (a5,NumberBuf-DT),a0
  1682.     bsr    StrToNum
  1683.     rts
  1684.  
  1685. ; Finds a space, tab, LF, CR or a null from a string pointed by A0. Returns
  1686. ; location in A0.
  1687.  
  1688. FindWhite:
  1689.     cmp.b    #" ",(a0)
  1690.     beq    .Found
  1691.     cmp.b    #TAB,(a0)
  1692.     beq    .Found
  1693.     cmp.b    #LF,(a0)
  1694.     beq    .Found
  1695.     cmp.b    #CR,(a0)
  1696.     beq    .Found
  1697.     tst.b    (a0)
  1698.     beq    .Found
  1699.     addq.l    #1,a0
  1700.     bra    FindWhite
  1701.  
  1702. .Found:
  1703.     rts
  1704.  
  1705. LoadPrefs:
  1706.     move.l    #PrefName,d1
  1707.     move.l    #MODE_OLDFILE,d2
  1708.     Call    Dos,Open
  1709.     move.l    d0,(a5,PrefHandle-DT)
  1710.     beq    .PrefsError
  1711.  
  1712.     move.l    d0,d1
  1713.     move.l    #FIB,d2
  1714.     Call    Dos,ExamineFH
  1715.     tst.l    d0
  1716.     beq    .PrefsError
  1717.  
  1718.     lea    FIB,a0            ; Alloc memory for the whole prefs file.
  1719.     move.l    fib_Size(a0),(a5,Size_Prefs-DT)
  1720.     move.l    (a5,Size_Prefs-DT),d0
  1721.     moveq    #0,d1
  1722.     Call    Exec,AllocMem
  1723.     move.l    d0,(a5,PrefPtr-DT)
  1724.     move.l    d0,(a5,PrefDecode-DT)
  1725.     beq    .PrefsError
  1726.  
  1727.     move.l    (a5,PrefHandle-DT),d1    ; Read the prefs file in the buf.
  1728.     move.l    (a5,PrefPtr-DT),d2
  1729.     move.l    (a5,Size_Prefs-DT),d3
  1730.     Call    Dos,Read
  1731.     cmp.l    #-1,d0
  1732.     beq    .PrefsError
  1733.  
  1734. .ContDecode:
  1735.     move.l    (a5,PrefDecode-DT),a0    ; Get the current address in the prefs
  1736.     bsr    SkipCrap        ; file, and skip comments & whitespace.
  1737.     tst.b    (a0)            ; If we are at a null, we are at the
  1738.     beq    EndPrefs        ; end of the file.
  1739.     bsr    CopySymbol        ; Otherwise in the start of a symbol,
  1740.     tst.l    d0            ; copy it and check for error.
  1741.     beq    EndPrefs        ; If error, exit.
  1742.     move.l    a0,(a5,PrefDecode-DT)    ; Save the new address.
  1743.     bsr    DetermineArg        ; Decode the argument for the option,
  1744.     move.l    d0,-(sp)        ; and save it in D0.
  1745.  
  1746.     lea    (a5,CopySymBuf-DT),a0    ; Compare the found option to those
  1747.     lea    Text_ANSIStrip,a1    ; we know, and branch to a corresponding
  1748.     bsr    StrCmp            ; subroutine.
  1749.     tst.l    d0
  1750.     beq    .Opt_ANSIStrip
  1751.  
  1752.     lea    (a5,CopySymBuf-DT),a0
  1753.     lea    Text_INStrip,a1
  1754.     bsr    StrCmp
  1755.     tst.l    d0
  1756.     beq    .Opt_INStrip
  1757.  
  1758.     lea    (a5,CopySymBuf-DT),a0
  1759.     lea    Text_ConvBuf,a1
  1760.     bsr    StrCmp
  1761.     tst.l    d0
  1762.     beq    .Opt_ConvBuf
  1763.  
  1764.     lea    (a5,CopySymBuf-DT),a0
  1765.     lea    Text_MakeEOLs,a1
  1766.     bsr    StrCmp
  1767.     tst.l    d0
  1768.     beq    .Opt_MakeEOLs
  1769.  
  1770.     lea    (a5,CopySymBuf-DT),a0
  1771.     lea    Text_EndSpaceRemoval,a1
  1772.     bsr    StrCmp
  1773.     tst.l    d0
  1774.     beq    .Opt_EndSpaceRemoval
  1775.  
  1776.     lea    (a5,CopySymBuf-DT),a0
  1777.     lea    Text_PowerPackOutput,a1
  1778.     bsr    StrCmp
  1779.     tst.l    d0
  1780.     beq    .Opt_PowerPackOutput
  1781.  
  1782.     lea    (a5,CopySymBuf-DT),a0
  1783.     lea    Text_SpacesToTabs,a1
  1784.     bsr    StrCmp
  1785.     tst.l    d0
  1786.     beq    .Opt_SpacesToTabs
  1787.  
  1788.     lea    (a5,CopySymBuf-DT),a0
  1789.     lea    Text_TabsToSpaces,a1
  1790.     bsr    StrCmp
  1791.     tst.l    d0
  1792.     beq    .Opt_TabsToSpaces
  1793.  
  1794.     lea    (a5,CopySymBuf-DT),a0
  1795.     lea    Text_TickDelay,a1
  1796.     bsr    StrCmp
  1797.     tst.l    d0
  1798.     beq    .Opt_TickDelay
  1799.  
  1800.     lea    (a5,CopySymBuf-DT),a0
  1801.     lea    Text_TempDir,a1
  1802.     bsr    StrCmp
  1803.     tst.l    d0
  1804.     beq    .Opt_TempDir
  1805.  
  1806.     lea    (a5,CopySymBuf-DT),a0
  1807.     lea    Text_LhAPack,a1
  1808.     bsr    StrCmp
  1809.     tst.l    d0
  1810.     beq    .Opt_LhAPack
  1811.  
  1812.     addq.l    #4,sp            ; Pop D0 ("arg") from stack.
  1813.     lea    (a5,PrintBuf-DT),a0    ; The option didn't match to anything
  1814.     lea    Text_UnknownOpt,a1    ; we know, so print an error.
  1815.     bsr    StrCpy
  1816.     lea    (a5,PrintBuf-DT),a0
  1817.     lea    (a5,CopySymBuf-DT),a1
  1818.     bsr    StrCat
  1819.  
  1820.     lea    (a5,PrintBuf-DT),a0
  1821.     lea    Text_Quote,a1
  1822.     bsr    StrCat
  1823.  
  1824.     lea    (a5,PrintBuf-DT),a0
  1825.     lea    Text_Period,a1
  1826.     bsr    StrCat
  1827.  
  1828.     lea    (a5,PrintBuf-DT),a0
  1829.     bsr    StrLFCat
  1830.     bsr    WritePrintBuf
  1831.     bra    .ContDecode        ; Get the next option.
  1832.  
  1833. ; Code for each different option. Stack has the option argument.
  1834. ; -1 True.  0 False.  >0 option value.
  1835.  
  1836. .Opt_ANSIStrip:
  1837.     move.l    (sp)+,d0
  1838.     bmi    .Opt_ANSIStripTrue
  1839.     clr.b    (a5,Flag_AStrip-DT)
  1840.     bra    .ContDecode
  1841.  
  1842. .Opt_ANSIStripTrue:
  1843.     st    (a5,Flag_AStrip-DT)
  1844.     bra    .ContDecode
  1845.  
  1846. .Opt_INStrip:
  1847.     move.l    (sp)+,d0
  1848.     bmi    .BadOptArg
  1849.     bne.b    .Opt_INStripTrue
  1850.     clr.b    (a5,Flag_INStrip-DT)
  1851.     bra    .ContDecode
  1852.  
  1853. .Opt_INStripTrue:
  1854.     cmp.l    #1,d0
  1855.     bne.b    .Opt_INStripCheck
  1856.     move.b    d0,(a5,Flag_INStrip-DT)
  1857.     bra    .ContDecode
  1858.  
  1859. .Opt_INStripCheck:
  1860.     cmp.l    #2,d0
  1861.     bne.b    .BadOptArg
  1862.     move.b    d0,(a5,Flag_INStrip-DT)
  1863.     bra    .ContDecode
  1864.  
  1865. .Opt_ConvBuf:
  1866.     move.l    (sp)+,d0
  1867.     bmi    .Opt_ConvBufTrue
  1868.     st    (a5,Mode_NoBuffer-DT)
  1869.     bra    .ContDecode
  1870.  
  1871. .Opt_ConvBufTrue:
  1872.     clr.b    (a5,Mode_NoBuffer-DT)
  1873.     bra    .ContDecode
  1874.  
  1875. .Opt_MakeEOLs:
  1876.     move.l    (sp)+,d0
  1877.     beq    .ContDecode
  1878.     IFD    Code020
  1879.     cmp2.b    .MakeEOLsRange,d0
  1880.     bcs    .BadOptArg
  1881.     ENDC
  1882.     IFND    Code020
  1883.     cmp.b    #1,d0
  1884.     bcs    .BadOptArg
  1885.     cmp.b    #99,d0
  1886.     bhi    .BadOptArg
  1887.     ENDC
  1888.     move.b    d0,(a5,Size_MakeEOLs-DT)
  1889.     bra    .ContDecode
  1890.  
  1891.     IFD    Code020
  1892.  
  1893. .MakeEOLsRange:
  1894.     dc.b    1
  1895.     dc.b    99
  1896.  
  1897.     ENDC
  1898.  
  1899. .Opt_EndSpaceRemoval:
  1900.     move.l    (sp)+,d0
  1901.     beq    .Opt_EndSpaceRemoval1
  1902.     bra    .ContDecode
  1903.  
  1904. .Opt_EndSpaceRemoval1:
  1905.     tst.b    (a5,Size_MakeEOLs-DT)
  1906.     bne.b    .OptConflict
  1907.     st    (a5,Mode_NoCutSpace-DT)
  1908.     bra    .ContDecode
  1909.  
  1910. .Opt_PowerPackOutput:
  1911.     move.l    (sp)+,d0
  1912.     bne.b    .Opt_PowerPackOutput1
  1913.     bra.b    .ContDecode
  1914.  
  1915. .Opt_PowerPackOutput1:
  1916.     st    (a5,Flag_CrunchBuf-DT)
  1917.     bra.b    .ContDecode
  1918.  
  1919. .Opt_TempDir:
  1920.     move.l    (sp)+,d0
  1921.     cmp.l    #-1,d0
  1922.     beq    .ContDecode        ; TempDir was OFF.
  1923.     cmp.l    #-2,d0
  1924.     bne    .BadTempDir        ; The argument wasn't a string? Error.
  1925.     lea    (a5,TempDir-DT),a0
  1926.     lea    (a5,StrBuf-DT),a1
  1927.     bsr    StrCpy
  1928.     move.l    #TempDir,d1
  1929.     move.l    #ACCESS_READ,d2
  1930.     Call    Dos,Lock
  1931.     move.l    d0,d1
  1932.     beq    .BadTempDir        ; Can't find TempDir? Error.
  1933.     move.l    d0,-(sp)
  1934.     move.l    #FIB,d2
  1935.     Call    Dos,Examine
  1936.     move.l    d0,-(sp)
  1937.     move.l    4(sp),d1
  1938.     Call    Dos,UnLock
  1939.     move.l    (sp)+,d0        ; Can't examine TempDir? Error.
  1940.     beq    .BadTempDir
  1941.     addq.l    #4,sp            ; Get rid of the lock on the stack.
  1942.     lea    FIB,a0
  1943.     tst.l    fib_DirEntryType(a0)    ; Not a directory? Error.
  1944.     beq    .BadTempDir
  1945.     bmi    .BadTempDir
  1946.     bra.w    .ContDecode
  1947.  
  1948. .BadTempDir:
  1949.     clr.b    (a5,TempDir-DT)
  1950.     bra    .BadOptArg
  1951.  
  1952. .Opt_SpacesToTabs:
  1953.     move.l    (sp)+,d0
  1954.     beq    .ContDecode
  1955.     IFD    Code020
  1956.     cmp2.b    .SpacesToTabsRange,d0
  1957.     bcs    .BadOptArg
  1958.     ENDC
  1959.     IFND    Code020
  1960.     cmp.b    #2,d0
  1961.     bcs    .BadOptArg
  1962.     cmp.b    #16,d0
  1963.     bhi    .BadOptArg
  1964.     ENDC
  1965.     tst.b    (a5,TabSize-DT)
  1966.     bne.b    .OptConflict
  1967.     move.b    d0,(a5,SpaceSize-DT)
  1968.     move.b    d0,(a5,TabSize-DT)
  1969.     bra    .ContDecode
  1970.  
  1971.     IFD    Code020
  1972.  
  1973. .SpacesToTabsRange:
  1974.     dc.b    2
  1975.     dc.b    16
  1976.  
  1977.     ENDC
  1978.  
  1979. .Opt_TabsToSpaces:
  1980.     move.l    (sp)+,d0
  1981.     beq    .ContDecode
  1982.     IFD    Code020
  1983.     cmp2.b    .TabsToSpacesRange,d0
  1984.     bcs    .BadOptArg
  1985.     ENDC
  1986.     IFND    Code020
  1987.     cmp.b    #1,d0
  1988.     bcs    .BadOptArg
  1989.     cmp.b    #16,d0
  1990.     bhi    .BadOptArg
  1991.     ENDC
  1992.     tst.b    (a5,SpaceSize-DT)
  1993.     bne    .OptConflict
  1994.     move.b    d0,(a5,TabSize-DT)
  1995.     bra    .ContDecode
  1996.  
  1997.     IFD    Code020
  1998.  
  1999. .TabsToSpacesRange:
  2000.     dc.b    1
  2001.     dc.b    16
  2002.  
  2003.     ENDC
  2004.  
  2005. .Opt_TickDelay:
  2006.     move.l    (sp)+,d0
  2007.     IFD    Code020
  2008.     cmp2.b    .TickRange,d0
  2009.     bcs    .TickVB
  2010.     ENDC
  2011.     IFND    Code020
  2012.     cmp.b    #1,d0
  2013.     bcs    .TickVB
  2014.     cmp.b    #255,d0
  2015.     bhi    .TickVB
  2016.     ENDC
  2017.     move.b    d0,(a5,TickDelay-DT)
  2018.     bra    .ContDecode
  2019.  
  2020. .TickVB:
  2021.     move.l    4.w,a6
  2022.     move.l    VBlankFrequency(a6),(a5,TickDelay-DT)
  2023.     bra    .ContDecode
  2024.  
  2025.     IFD    Code020
  2026.  
  2027. .TickRange:
  2028.     dc.b    1
  2029.     dc.b    255
  2030.  
  2031.     ENDC
  2032.  
  2033. .Opt_LhAPack:
  2034.     move.l    (sp)+,d0
  2035.     beq.b    .Opt_LhAPackOff
  2036.     cmp.l    #-1,d0
  2037.     bne    .BadOptArg
  2038.     tst.b    (a5,Flag_CrunchBuf-DT)
  2039.     bne.b    .OptConflict
  2040.     st    (a5,Flag_LhAPack-DT)
  2041.     bra    .ContDecode
  2042.  
  2043. .Opt_LhAPackOff:
  2044.     clr.b    (a5,Flag_LhAPack-DT)
  2045.     bra    .ContDecode
  2046.  
  2047. .BadOptArg:                ; Jumped into, if the arg for the option
  2048.     lea    (a5,PrintBuf-DT),a0    ; made no sense.
  2049.     lea    Text_BadOptArg,a1
  2050.     bsr    StrCpy
  2051.  
  2052.     lea    (a5,PrintBuf-DT),a0
  2053.     lea    (a5,CopySymBuf-DT),a1
  2054.     bsr    StrCat
  2055.  
  2056.     lea    (a5,PrintBuf-DT),a0
  2057.     lea    Text_Quote,a1
  2058.     bsr    StrCat
  2059.  
  2060.     lea    (a5,PrintBuf-DT),a0
  2061.     lea    Text_Period,a1
  2062.     bsr    StrCat
  2063.  
  2064.     lea    (a5,PrintBuf-DT),a0
  2065.     bsr    StrLFCat
  2066.     bsr    WritePrintBuf
  2067.     bra    .ContDecode
  2068.  
  2069. .OptConflict:                ; Jumped into if an option caused a
  2070.     lea    (a5,PrintBuf-DT),a0    ; conflict with another one.
  2071.     clr.b    (a0)
  2072.     lea    Text_Error,a1
  2073.     bsr    StrCat
  2074.     lea    (a5,PrintBuf-DT),a0
  2075.     lea    Text_OptConflict,a1
  2076.     bsr    StrCat
  2077.     lea    (a5,PrintBuf-DT),a0
  2078.     bsr    StrLFCat
  2079.     bsr    WritePrintBuf
  2080.     bra    EndPrefs
  2081.  
  2082. .PrefsError:                ; Error loading the prefs.
  2083.     move.l    #Text_PrefsError,d2
  2084.     bsr    PrintText
  2085.  
  2086. EndPrefs:
  2087.     move.l    (a5,PrefHandle-DT),d1    ; If we opened the prefs file, close it.
  2088.     beq.b    .EndPrefs1
  2089.     Call    Dos,Close
  2090.  
  2091. .EndPrefs1:
  2092.     move.l    (a5,PrefPtr-DT),a1    ; If we allocated memory for the prefs,
  2093.     IFD    Code020            ; free it.
  2094.     tst.l    a1
  2095.     ENDC
  2096.     IFND    Code020
  2097.     cmp.l    #0,a1
  2098.     ENDC
  2099.     bne.b    .EndPrefs2
  2100.     rts
  2101.  
  2102. .EndPrefs2:
  2103.     move.l    (a5,Size_Prefs-DT),d0
  2104.     Call    Exec,FreeMem
  2105.     rts
  2106.  
  2107. SkipCrap:
  2108.     move.b    (a0),d0            ; Skip characters other than [A-Z] [a-z]
  2109.     IFD    Code020            ; and comments (start with semicolon).
  2110.     cmp2.b    CapRange,d0        ; Comment is from the semicolon to the
  2111.     bcs.b    .CheckLow        ; EOL.
  2112.     ENDC
  2113.     IFND    Code020
  2114.     cmp.b    #"A",d0
  2115.     bcs.b    .CheckLow
  2116.     cmp.b    #"Z",d0
  2117.     bhi.b    .CheckLow
  2118.     ENDC
  2119.     rts
  2120.  
  2121. .CheckLow:
  2122.     IFD    Code020
  2123.     cmp2.b    LowRange,d0
  2124.     bcs.b    .CheckOther
  2125.     ENDC
  2126.     IFND    Code020
  2127.     cmp.b    #"a",d0
  2128.     bcs.b    .CheckOther
  2129.     cmp.b    #"z",d0
  2130.     bhi.b    .CheckOther
  2131.     ENDC
  2132.     rts
  2133.  
  2134. .CheckOther:
  2135.     cmp.b    #";",(a0)
  2136.     bne    .SkipChar
  2137.     bsr    SkipLine
  2138.     subq.l    #1,a0
  2139.  
  2140. .SkipChar:
  2141.     addq.l    #1,a0            ; Check that we don't run out of the
  2142.     tst.b    (a0)            ; string, and continue.
  2143.     bne.b    SkipCrap
  2144.     rts
  2145.  
  2146. CopySymbol:
  2147.     lea    (a5,CopySymBuf-DT),a1
  2148.  
  2149. .ContCopy:
  2150.     move.b    (a0),d0            ; A symbol only has chars [A-Z] [a-z],
  2151.     IFD    Code020            ; and ends in equal sign. Otherwise
  2152.     cmp2.b    CapRange,d0        ; return error.
  2153.     bcs    .CheckLow
  2154.     ENDC
  2155.     IFND    Code020
  2156.     cmp.b    #"A",d0
  2157.     bcs.b    .CheckLow
  2158.     cmp.b    #"Z",d0
  2159.     bhi.b    .CheckLow
  2160.     ENDC
  2161.     move.b    (a0)+,(a1)+
  2162.     bra    .ContCopy
  2163.  
  2164. .CheckLow:
  2165.     IFD    Code020
  2166.     cmp2.b    LowRange,d0
  2167.     bcs.b    .CheckOther
  2168.     ENDC
  2169.     IFND    Code020
  2170.     cmp.b    #"a",d0
  2171.     bcs.b    .CheckOther
  2172.     cmp.b    #"z",d0
  2173.     bhi.b    .CheckOther
  2174.     ENDC
  2175.     move.b    (a0)+,(a1)+
  2176.     bra.b    .ContCopy
  2177.  
  2178. .CheckOther:
  2179.     tst.b    (a0)
  2180.     bne.b    .StillLeft
  2181.     moveq    #0,d0            ; If we ran out of the string in the
  2182.     rts                ; process, return an error.
  2183.  
  2184. .StillLeft:
  2185.     cmp.b    #"=",(a0)        ; Only a-Z & =, otherwise skip the whole
  2186.     bne.b    .SkipThisLine        ; line.
  2187.     addq.l    #1,a0            ; Skip the "=".
  2188.     clr.b    (a1)            ; Close the symbol string.
  2189.     moveq    #-1,d0            ; Everything okay.
  2190.     rts
  2191.  
  2192. .SkipThisLine:                ; Skip all characters until an LF is
  2193.     bsr    SkipLine        ; found, or end of string hit.
  2194.     bra    CopySymbol
  2195.  
  2196. SkipLine:
  2197.     cmp.b    #"\n",(a0)+
  2198.     bne    .SkipLine2
  2199.     rts
  2200.  
  2201. .SkipLine2:
  2202.     tst.b    (a0)
  2203.     bne.b    SkipLine
  2204.     rts
  2205.  
  2206. DetermineArg:
  2207.     lea    (a5,StrBuf-DT),a1
  2208.  
  2209. .NextChar:
  2210.     cmp.b    #'"',(a0)        ; If starts with a quote, we have str.
  2211.     beq.b    .String
  2212.     cmp.b    #"O",(a0)        ; Copy bytes that match O,N,F,0-9.
  2213.     beq.b    .GoodChar
  2214.     cmp.b    #"N",(a0)
  2215.     beq.b    .GoodChar
  2216.     cmp.b    #"F",(a0)
  2217.     beq.b    .GoodChar
  2218.     cmp.b    #"0",(a0)
  2219.     bcc.b    .CheckOther
  2220.     bra.b    .Decode            ; When none of those was found, check
  2221.                     ; what we got.
  2222. .CheckOther:
  2223.     cmp.b    #"9",(a0)
  2224.     bls.b    .GoodChar
  2225.     bra.b    .Decode
  2226.  
  2227. .GoodChar:
  2228.     move.b    (a0)+,(a1)+
  2229.     bra.b    .NextChar
  2230.  
  2231. .Decode:
  2232.     clr.b    (a1)            ; Close the copied string.
  2233.     lea    (a5,StrBuf-DT),a0
  2234.     cmp.b    #"O",(a0)        ; If it starts with "O", it's ON | OFF.
  2235.     beq.b    .Boolean
  2236.     bsr    StrToNum        ; Not a str or a bool, must be number.
  2237.     rts                ; Return the number.
  2238.  
  2239. .Boolean:
  2240.     cmp.b    #"N",1(a0)
  2241.     beq.b    .True
  2242.     moveq    #0,d0            ; False.
  2243.     rts
  2244.  
  2245. .True:
  2246.     moveq    #-1,d0
  2247.     rts
  2248.  
  2249. .String:
  2250.     move.w    #256,d0            ; Max 256 bytes tolerated.
  2251.     addq.l    #1,a0            ; Skip the initial quote.
  2252.  
  2253. .Copy:
  2254.     cmp.b    #'"',(a0)        ; Another quote ends the string.
  2255.     beq.b    .Finished
  2256.     tst.b    (a0)            ; Check we don't run out of the data.
  2257.     beq.b    .BadString
  2258.     move.b    (a0)+,(a1)+
  2259.     subq.w    #1,d0            ; One less free byte in A1.
  2260.     beq.b    .BadString
  2261.     bra.b    .Copy
  2262.  
  2263. .Finished:
  2264.     clr.b    (a1)            ; Finished the copied string.
  2265.     moveq    #-2,d0
  2266.     rts
  2267.  
  2268. .BadString:                ; Bad string, return OFF.
  2269.     moveq    #0,d0
  2270.     rts
  2271.  
  2272. PrintReading:                ; Print "Reading".
  2273.     SaveR
  2274.     lea    (a5,PrintBuf-DT),a0
  2275.     clr.b    (a0)
  2276.     lea    Text_Reading,a1
  2277.     bsr    StrCat
  2278.     lea    (a5,PrintBuf-DT),a0
  2279.     lea    Text_ClearEOL,a1
  2280.     bsr    StrCat
  2281.     lea    (a5,PrintBuf-DT),a0
  2282.     lea    Text_CR,a1
  2283.     bsr    StrCat
  2284.     bsr    WritePrintBuf
  2285.     LoadR
  2286.     rts
  2287.  
  2288. PrintWriting:                ; Print "Writing".
  2289.     SaveR
  2290.     lea    (a5,PrintBuf-DT),a0
  2291.     clr.b    (a0)
  2292.     lea    Text_Writing,a1
  2293.     bsr    StrCat
  2294.     lea    (a5,PrintBuf-DT),a0
  2295.     lea    Text_ClearEOL,a1
  2296.     bsr    StrCat
  2297.     lea    (a5,PrintBuf-DT),a0
  2298.     lea    Text_CR,a1
  2299.     bsr    StrCat
  2300.     bsr    WritePrintBuf
  2301.     LoadR
  2302.     rts
  2303.  
  2304. ; Allocates the read and write buffers for the file depending on free
  2305. ; memory.
  2306.  
  2307. AllocBuffers:
  2308.     move.l    (a5,CurrentLink-DT),a0
  2309.     move.l    (a5,SourceLen-DT),d0
  2310.     tst.b    (a5,Mode_NoBuffer-DT)    ; We have a full read buffer, so
  2311.     beq.b    .OnlyDest        ; allocate only the write buffer.
  2312.     move.l    d0,d1
  2313.     lsr.l    #3,d1
  2314.     add.l    d0,d0
  2315.     add.l    d1,d0            ; D0 = 212% D0
  2316.     bra.b    .DoAlloc
  2317.  
  2318. .OnlyDest:
  2319.     move.l    d0,d1
  2320.     lsr.l    #3,d1
  2321.     add.l    d1,d0            ; D0 = 112% D0
  2322.  
  2323. .DoAlloc:
  2324.     move.l    d0,-(sp)
  2325.     moveq    #0,d1
  2326.     Call    Exec,AllocMem
  2327.     tst.l    d0
  2328.     beq.b    .NewTry
  2329.     move.l    d0,(a5,BigBufPtr-DT)
  2330.     move.l    (sp)+,(a5,BigBufSize-DT)
  2331.  
  2332.     tst.b    (a5,Mode_NoBuffer-DT)    ; We have a full read buffer, so
  2333.     beq.b    .SetOnlyDest        ; allocate only the write buffer.
  2334.     move.l    (a5,BigBufSize-DT),d0
  2335.     lsr.l    #1,d0
  2336.     move.l    (a5,BigBufPtr-DT),(a5,SourcePointer-DT)
  2337.     move.l    d0,(a5,Size_SrcBuf-DT)
  2338.     move.l    (a5,BigBufPtr-DT),(a5,DestPointer-DT)
  2339.     add.l    d0,(a5,DestPointer-DT)
  2340.     move.l    d0,(a5,Size_DstBuf-DT)
  2341.     rts
  2342.  
  2343. .SetOnlyDest:
  2344.     move.l    (a5,BigBufSize-DT),(a5,Size_DstBuf-DT)
  2345.     move.l    (a5,BigBufPtr-DT),(a5,DestPointer-DT)
  2346.     rts
  2347.  
  2348. .NewTry:
  2349.     move.l    (sp)+,d0
  2350.     lsr.l    #2,d0            ; D0 = 75% D0
  2351.     move.l    d0,d1
  2352.     add.l    d0,d0
  2353.     add.l    d1,d0
  2354.     cmp.l    #102400,d0        ; Lower limit of 100kB for buffer(s).
  2355.     bcs.b    .NoAllocPossib
  2356.     bra.b    .DoAlloc
  2357.  
  2358. .NoAllocPossib:
  2359.     move.l    #Text_NoMemConvert,d2
  2360.     bra    ShowErr
  2361.  
  2362. CrunchDestFile:
  2363.     st    (a5,Flag_CrunchTried-DT)
  2364.     bsr    ClearPrintBuf
  2365.     lea    Text_Crunching1,a0
  2366.     bsr    AddPrintBuf
  2367.     lea    (a5,DestName-DT),a0
  2368.     bsr    AddPrintBuf
  2369.     lea    Text_Crunching2,a0
  2370.     bsr    AddPrintBuf
  2371.     bsr    WritePrintBuf
  2372.  
  2373.     tst.b    (a5,Flag_LhAPack-DT)
  2374.     bne    DoLhAPack
  2375.  
  2376.     move.l    #CrunchSrcName,d1    ; Open the DestName file.
  2377.     move.l    #ACCESS_READ,d2
  2378.     Call    Dos,Lock
  2379.     move.l    d0,(a5,DestLock-DT)
  2380.     beq.w    Err_NoCrunchFile    ; If no lock, cannot crunch.
  2381.     move.l    (a5,DestLock-DT),d1    ; Otherwise check it
  2382.     move.l    #FIB,d2
  2383.     Call    Dos,Examine
  2384.     move.l    d0,-(sp)        ; Save result code
  2385.     move.l    (a5,DestLock-DT),d1
  2386.     Call    Dos,UnLock
  2387.     clr.l    (a5,DestLock-DT)
  2388.     move.l    (sp)+,d0        ; Boolean
  2389.     beq.w    Err_NoCrunchFile    ; If no Examine(), cannot crunch.
  2390.     lea    FIB,a0
  2391.     move.l    fib_Size(a0),(a5,CrSize-DT)
  2392.  
  2393.     move.l    (a5,CrSize-DT),d0
  2394.     moveq    #0,d1
  2395.     Call    Exec,AllocMem
  2396.     move.l    d0,(a5,CrBuf-DT)
  2397.     beq    Err_NoCrunchMem
  2398.  
  2399.     move.l    #CrunchSrcName,d1
  2400.     move.l    #MODE_OLDFILE,d2
  2401.     Call    Dos,Open
  2402.     move.l    d0,(a5,CrFile-DT)
  2403.  
  2404.     bsr    PrintReading
  2405.     move.l    (a5,CrFile-DT),d1
  2406.     move.l    (a5,CrBuf-DT),d2
  2407.     move.l    (a5,CrSize-DT),d3
  2408.     Call    Dos,Read
  2409.     cmp.l    #-1,d0
  2410.     beq    Err_CrunchReadWrite
  2411.  
  2412.     move.l    (a5,CrFile-DT),d1
  2413.     Call    Dos,Close
  2414.     clr.l    (a5,CrFile-DT)
  2415.  
  2416.     move.l    #CRUN_BEST,d0
  2417.     move.l    #SPEEDUP_BUFFLARGE,d1
  2418.  
  2419.     lea    CrunchProgress,a0    ; Routine to be called for progress
  2420.     sub.l    a1,a1
  2421.     Call    PP,ppAllocCrunchInfo
  2422.     move.l    d0,(a5,CrCrunchInfo-DT)
  2423.     beq    Err_NoCrunchMem
  2424.  
  2425.     move.l    (a5,CrCrunchInfo-DT),a0
  2426.     move.l    (a5,CrBuf-DT),a1
  2427.     move.l    (a5,CrSize-DT),d0
  2428.  
  2429.     Call    PP,ppCrunchBuffer
  2430.  
  2431.     move.l    d0,(a5,CrDestSize-DT)
  2432.  
  2433.     cmp.l    #PP_CRUNCHABORTED,d0
  2434.     beq    BreakPressed
  2435.     cmp.l    #PP_BUFFEROVERFLOW,d0
  2436.     beq    Err_CrunchOverflow
  2437.  
  2438.     move.l    #DestName,d1
  2439.     move.l    #MODE_NEWFILE,d2
  2440.     Call    Dos,Open
  2441.     move.l    d0,(a5,CrFile-DT)
  2442.     beq    Err_CrunchReadWrite
  2443.  
  2444.     move.l    (a5,CrFile-DT),d0
  2445.     move.l    #CRUN_BEST,d1
  2446.     move.l    #FALSE,d2
  2447.     moveq    #0,d3
  2448.     Call    PP,ppWriteDataHeader
  2449.     tst.l    d0
  2450.     beq    Err_CrunchReadWrite
  2451.  
  2452.     bsr    PrintWriting
  2453.     move.l    (a5,CrFile-DT),d1
  2454.     move.l    (a5,CrBuf-DT),d2
  2455.     move.l    (a5,CrDestSize-DT),d3
  2456.     Call    Dos,Write
  2457.     cmp.l    #-1,d0
  2458.     beq    Err_CrunchReadWrite
  2459.  
  2460.     move.l    (a5,CrFile-DT),d1
  2461.     Call    Dos,Close
  2462.     clr.l    (a5,CrFile-DT)
  2463.  
  2464.     move.l    (a5,CrBuf-DT),a1
  2465.     move.l    (a5,CrSize-DT),d0
  2466.     Call    Exec,FreeMem
  2467.     clr.l    (a5,CrBuf-DT)
  2468.  
  2469.     move.l    (a5,CrCrunchInfo-DT),a0
  2470.     Call    PP,ppFreeCrunchInfo
  2471.     clr.l    (a5,CrCrunchInfo-DT)
  2472.  
  2473.     move.l    (a5,CrSize-DT),-(sp)
  2474.     move.l    (a5,CrDestSize-DT),-(sp)
  2475.     move.l    (a5,CrSize-DT),-(sp)
  2476.     st    (a5,Flag_StatsDue-DT)
  2477.     bsr    CrunchProgress
  2478.     add.l    #12,sp
  2479.  
  2480.     move.l    #Text_LF,d2
  2481.     bsr    PrintText
  2482.     move.l    #Text_LF,d2
  2483.     bsr    PrintText
  2484.     rts
  2485.  
  2486. DoLhAPack:
  2487.     lea    (a5,StrBuf-DT),a0
  2488.     lea    Text_LhALine,a1
  2489.     bsr    StrCpy
  2490.     lea    (a5,StrBuf-DT),a0
  2491.     bsr    StrEnd
  2492.     lea    (a5,DestName-DT),a1
  2493.     bsr    MakeLhAName
  2494.     lea    (a5,StrBuf-DT),a0
  2495.     lea    Text_Space,a1
  2496.     bsr    StrCat
  2497.     lea    (a5,StrBuf-DT),a0
  2498.     lea    (a5,CrunchSrcName-DT),a1
  2499.     bsr    StrCat
  2500.     move.l    #StrBuf,d2
  2501.     bsr    PrintText
  2502.     move.l    #Text_LF,d2
  2503.     bsr    PrintText
  2504.  
  2505.     move.l    #StrBuf,d1
  2506.     move.l    #LhATagList,d2
  2507.     Call    Dos,SystemTagList
  2508.     move.l    d0,(a5,ErrorCode-DT)
  2509.     bne    EndProgramErr
  2510.     st    (a5,Flag_DidLhAPack-DT)
  2511.     move.l    #Text_LF,d2
  2512.     bsr    PrintText
  2513.     rts
  2514.  
  2515. ; A0  Ptr for the converted name.
  2516. ; A1  Ptr to the original name.
  2517.  
  2518. MakeLhAName:
  2519.     movem.l    a0-a1,-(sp)
  2520.     move.l    a1,a0
  2521.     bsr    StrLen
  2522.     move.w    d0,(a5,MakeNameLen-DT)
  2523.     movem.l    (sp)+,a0-a1
  2524.     move.l    a0,-(sp)        ; Copy the original name to destination.
  2525.     bsr    StrCpy
  2526.     move.l    (sp)+,a0
  2527.     bsr    StrEnd
  2528.     move.w    (a5,MakeNameLen-DT),d0
  2529.     Say    "Length:"
  2530.     ShowReg    d0
  2531.     cmp.l    #3,d0            ; Doesn't have space for the simplest,
  2532.     bcs.b    .AddSuf            ; "a.b", so just add the suffix.
  2533.     subq.l    #2,a0
  2534.     subq.l    #2,d0
  2535.     cmp.b    #".",(a0)        ; ".x"
  2536.     beq.b    .KillOldSuffix
  2537.     subq.l    #1,a0
  2538.     subq.l    #1,d0
  2539.     beq.b    .AddSuf
  2540.     cmp.b    #".",(a0)        ; ".xx"
  2541.     beq.b    .KillOldSuffix
  2542.     subq.l    #1,a0
  2543.     subq.l    #1,d0
  2544.     beq.b    .AddSuf
  2545.     cmp.b    #".",(a0)        ; ".xxx"
  2546.     beq.b    .KillOldSuffix
  2547.     bra.b    .AddSuf
  2548.  
  2549. .KillOldSuffix:
  2550.     lea    Text_LhASuffix,a1    ; ".LHA"
  2551.     bsr    StrCpy            ; Copy the suffix on the old suffix.
  2552.     rts
  2553.  
  2554. .AddSuf:
  2555.     bsr    StrEnd
  2556.     lea    Text_LhASuffix,a1    ; ".LHA"
  2557.     bsr    StrCpy
  2558.     rts
  2559.  
  2560. CrunchProgress:
  2561.     SaveR
  2562.     lea    DT,a5
  2563.     tst.b    (a5,Flag_StatsDue-DT)
  2564.     bne.b    .DoStats
  2565.     LoadR
  2566.     moveq    #-1,d0
  2567.     rts
  2568.  
  2569. .DoStats:
  2570.     clr.b    (a5,Flag_StatsDue-DT)
  2571.  
  2572.     moveq    #0,d0            ; Get the signals.
  2573.     moveq    #0,d1
  2574.     Call    Exec,SetSignal
  2575.     btst    #SIGBREAKB_CTRL_C,d0    ; Check if ^C was pressed.
  2576.     bne.b    .Abort
  2577.  
  2578.     bsr    ClearPrintBuf
  2579.     lea    Text_Done,a0
  2580.     bsr    AddPrintBuf
  2581.  
  2582.     move.l    4+60(sp),d0
  2583.     move.l    12+60(sp),d1
  2584.     bsr    Percentage
  2585.     bsr    NumPrintBuf
  2586.  
  2587.     lea    Text_PercentSign,a0
  2588.     bsr    AddPrintBuf
  2589.  
  2590.     lea    Text_Gain,a0
  2591.     bsr    AddPrintBuf
  2592.  
  2593.     move.l    8+60(sp),d0
  2594.     move.l    4+60(sp),d1
  2595.     bsr    Percentage
  2596.     moveq    #100,d1
  2597.     sub.l    d0,d1
  2598.     move.l    d1,d0
  2599.     bsr    NumPrintBuf
  2600.  
  2601.     lea    Text_PercentSign,a0
  2602.     bsr    AddPrintBuf
  2603.  
  2604.     lea    Text_CR,a0
  2605.     bsr    AddPrintBuf
  2606.  
  2607.     bsr    WritePrintBuf
  2608.  
  2609.     LoadR    
  2610.     moveq    #-1,d0
  2611.     rts
  2612.  
  2613. .Abort:
  2614.     LoadR
  2615.     moveq    #0,d0
  2616.     rts
  2617.  
  2618. ; A0 - Ptr to pattern.
  2619.  
  2620. FormFileLinks:
  2621.     move.l    a0,d1            ; Get the first file.
  2622.     move.l    #MyAnchor,d2
  2623.     pea    (a5,FileLinkBase-DT)
  2624.     Call    Dos,MatchFirst
  2625.     st    (a5,Flag_AnchorUsed-DT)
  2626.     tst.l    d0
  2627.     bne.b    .NoMatch
  2628.  
  2629. .GetNextFile:
  2630.     move.l    #fl_SIZEOF,d0        ; Allocate a new FileLink.
  2631.     move.l    #MEMF_CLEAR,d1
  2632.     Call    Exec,AllocMem
  2633.     move.l    (sp)+,a0        ; Link it to the old FileLink.
  2634.     move.l    a0,(a5,OldFileLinkPtr-DT)
  2635.     move.l    d0,(a0)
  2636.     move.l    d0,a1            ; Prepare copying data from the anchor
  2637.  
  2638. .UseOldLink:
  2639.     lea    MyAnchor+ap_Info,a0    ; to the FileLink.
  2640.     tst.l    (fib_DirEntryType,a0)
  2641.     bgt.b    .SkipDir        ; Skip directories.
  2642.     st    (a5,Flag_FileFound-DT)    ; Now we have at least one file.
  2643.     move.l    (fib_Size,a0),(fl_Size,a1)
  2644.     move.l    a1,-(sp)        ; Store for .GetNextFile linkage.
  2645.     lea    (fib_FileName,a0),a0    ; Copy the name from FIB to current
  2646.     lea    (fl_FileName,a1),a1    ; FileLink.
  2647.     exg    a0,a1
  2648.     bsr    StrCpy
  2649.     move.l    (sp),a1
  2650.     add.l    #fl_FullName,a1
  2651.     lea    MyAnchor+ap_Buf,a0
  2652.     exg    a0,a1
  2653.     bsr    StrCpy
  2654.  
  2655.     move.l    #MyAnchor,d1        ; Get the next file.
  2656.     Call    Dos,MatchNext
  2657.     tst.l    d0
  2658.     bne.b    .NoMatch
  2659.     bra    .GetNextFile
  2660.  
  2661. .SkipDir:
  2662.     move.l    a1,-(sp)
  2663.     move.l    #MyAnchor,d1
  2664.     Call    Dos,MatchNext
  2665.     move.l    (sp)+,a1
  2666.     tst.l    d0            ; Got a new file, copy the data to old
  2667.     beq.b    .UseOldLink        ; FileLink.
  2668.     move.l    #fl_SIZEOF,d0        ; No new file, kill this FileLink.
  2669.     Call    Exec,FreeMem
  2670.     move.l    (a5,OldFileLinkPtr-DT),a0
  2671.     clr.l    (a0)            ; Clear the link to next in the last true
  2672.     bra.b    .NoMatchNoStack        ; FileLink.
  2673.  
  2674. .NoMatch:
  2675.     addq.l    #4,sp
  2676.  
  2677. .NoMatchNoStack:
  2678.     lea    MyAnchor,a0        ; Check if ^C has been pressed.
  2679.     tst.l    ap_FoundBreak(a0)
  2680.     bne.b    BreakPressed
  2681.     Call    Dos,IoErr        ; Find the reason for stopping.
  2682.     cmp.l    #ERROR_NO_MORE_ENTRIES,d0
  2683.     bne.b    .RealError        ; If that wasn't the reason, we have an
  2684.     rts                ; error.
  2685.  
  2686. .RealError:
  2687.     st    (a5,Flag_Stop-DT)
  2688.     cmp.l    #ERROR_OBJECT_NOT_FOUND,d0
  2689.     beq    Err_NoSource
  2690.     cmp.l    #ERROR_DEVICE_NOT_MOUNTED,d0
  2691.     beq    Err_NoSource
  2692.     move.l    d0,d1
  2693.     move.l    #Text_Error,d2
  2694.     move.l    #PrintBuf,d3
  2695.     move.l    #256,d4
  2696.     Call    Dos,Fault
  2697.     lea    (a5,PrintBuf-DT),a0
  2698.     bsr    StrLFCat
  2699.     bsr    WritePrintBuf
  2700.     bra    EndProgramErr
  2701.  
  2702. InsertEOLs:
  2703.     move.l    (a5,EOLs-DT),d3        ; Insert "EOLs" EOLs.
  2704.     bne.b    .EOLsWaiting
  2705.     rts
  2706.  
  2707. .EOLsWaiting:
  2708.     clr.l    (a5,EOLs-DT)
  2709.     add.l    d3,d2            ; Add the number of LFs.
  2710.     tst.b    (a5,Mode-DT)        ; If ToPC or ToSF7, add a CR too.
  2711.     bpl.b    .DoInsertEOLs
  2712.     add.l    d3,d2            ; Add the number of CRs.
  2713.  
  2714. .DoInsertEOLs:
  2715.     subq.l    #1,d3
  2716.  
  2717. .DoInsert:
  2718.     bsr    InsertSingleEOL
  2719.     dbf.b    d3,.DoInsert
  2720.     rts
  2721.  
  2722. ; Inserts an EOL according to Mode, and adds D2.
  2723.  
  2724. InsertOneEOL:
  2725.     move.b    #LF,(a1)+
  2726.     tst.b    (a5,Mode-DT)        ; If ToPC or ToSF7, add a CR too.
  2727.     bmi.b    .ForeignEOL
  2728.     addq.l    #1,d2
  2729.     rts
  2730.  
  2731. .ForeignEOL:
  2732.     move.b    #CR,(a1)+
  2733.     addq.l    #2,d2
  2734.     rts
  2735.  
  2736. ; Inserts an EOL according to Mode, but does not add D2.
  2737.  
  2738. InsertSingleEOL:
  2739.     move.b    #LF,(a1)+
  2740.     tst.b    (a5,Mode-DT)        ; If ToPC or ToSF7, add a CR too.
  2741.     bmi.b    .ForeignEOL
  2742.     rts
  2743.  
  2744. .ForeignEOL:
  2745.     move.b    #CR,(a1)+
  2746.     rts
  2747.  
  2748. FlushArea:
  2749.     tst.b    (a5,TabSize-DT)        ; Insert buffered spaces and tabs to
  2750.     bne.b    .SpaceTabConv        ; the write buffer.
  2751.     lea    (a5,SpaceBuf-DT),a2
  2752.     move.l    (a5,SpaceNumber-DT),d3
  2753.     beq.b    .NothingToCopy
  2754.     add.l    d3,d2
  2755.     subq.l    #1,d3
  2756.  
  2757. .CopyArea:
  2758.     move.b    (a2)+,(a1)+
  2759.     dbf.b    d3,.CopyArea
  2760.  
  2761. .NothingToCopy:
  2762.     bsr    ResetArea
  2763.     rts
  2764.  
  2765. .SpaceTabConv:
  2766.     tst.b    (a5,PreSpace-DT)
  2767.     beq    .NoPreSpace
  2768.     move.b    #" ",(a1)+
  2769.     addq.l    #1,d2
  2770.  
  2771. .NoPreSpace:
  2772.     move.l    (a5,Tabs-DT),d3
  2773.     beq    .NoTabs
  2774.     add.l    d3,d2
  2775.     subq.l    #1,d3
  2776.  
  2777. .InsertTabs:
  2778.     move.b    #TAB,(a1)+
  2779.     dbf    d3,.InsertTabs
  2780.  
  2781. .NoTabs:
  2782.     move.l    (a5,SpaceNumber-DT),d3
  2783.     beq.b    .NoSpaces
  2784.     add.l    d3,d2
  2785.     subq.l    #1,d3
  2786.  
  2787. .InsertSpaces
  2788.     move.b    #" ",(a1)+
  2789.     dbf.b    d3,.InsertSpaces
  2790.  
  2791. .NoSpaces:
  2792.     bsr    ResetArea
  2793.     rts
  2794.  
  2795. ResetArea:
  2796.     tst.b    (a5,TabSize-DT)        ; Clear all buffered spaces and tabs.
  2797.     beq.b    .NoSpaceTabConv
  2798.     clr.l    (a5,SpaceNumber-DT)
  2799.     clr.l    (a5,Tabs-DT)
  2800.     clr.b    (a5,PreSpace-DT)
  2801.     rts
  2802.  
  2803. .NoSpaceTabConv:
  2804.     lea    (a5,SpaceBuf-DT),a2
  2805.     clr.l    (a5,SpaceNumber-DT)
  2806.     rts
  2807.  
  2808. BufChar:
  2809.     move.b    d0,(a2)+        ; No Space-Tab conversion active,
  2810.     addq.l    #1,(a5,SpaceNumber-DT)    ; buffer all area found.
  2811.     addq.w    #1,(a5,Col-DT)
  2812.     rts
  2813.  
  2814. SpaceConv:
  2815.     cmp.l    #1,(a5,SpaceNumber-DT)    ; If Spacenumber<1, don't try to convert
  2816.     bcc.b    .ContConv        ; to tabs.  No use, and time wasted in
  2817.     rts
  2818.  
  2819. .ContConv:
  2820.     move.w    (a5,Col-DT),d5
  2821.     ext.l    d5
  2822.     move.l    (a5,SpaceNumber-DT),d3
  2823.     move.b    (a5,SpaceSize-DT),d4
  2824.     IFD    Code020            ; Convert TabSize
  2825.     extb.l    d4
  2826.     ENDC
  2827.     IFND    Code020
  2828.     ext.w    d4
  2829.     ext.l    d4
  2830.     ENDC
  2831.     divu.w    d4,d5            ; If column is divisible by SpaceSize,
  2832.     swap    d5            ; it can be converted to a tab.
  2833.     tst.w    d5
  2834.     beq.b    .CanConv
  2835.     rts
  2836.  
  2837. .CanConv:
  2838.     cmp.l    #1,(a5,SpaceNumber-DT)    ; If only one space is won, instead
  2839.     beq.b    .GotPreSpace        ; of conversion, make it PreSpace.
  2840.     addq.l    #1,(a5,Tabs-DT)        ; More tabs.
  2841.     clr.l    (a5,SpaceNumber-DT)    ; Take the spaces out.
  2842.     rts
  2843.  
  2844. .GotPreSpace:
  2845.     st    (a5,PreSpace-DT)
  2846.     clr.l    (a5,SpaceNumber-DT)    ; Reset SpaceNumber.
  2847.     rts
  2848.  
  2849. TabConv:
  2850.     move.b    (a5,TabSize-DT),d4    ; TabSize = 0 means no Tabs2Spaces conv.
  2851.     IFD    Code020            ; Convert TabSize
  2852.     extb.l    d4
  2853.     ENDC
  2854.     IFND    Code020
  2855.     ext.w    d4
  2856.     ext.l    d4
  2857.     ENDC
  2858.     move.w    (a5,Col-DT),d3        ; Get current column.
  2859.     ext.l    d3
  2860.     divu.w    d4,d3            ; Divide column with TabSize -> we get
  2861.     swap    d3            ; the offset from last tab as chars.
  2862.     sub.w    d3,d4            ; Get the # of spaces to the next tab.
  2863.     add.l    d4,(a5,SpaceNumber-DT)    ; Add the converted spaces to SpaceBuf.
  2864.     add.w    d4,(a5,Col-DT)        ; And add column too.
  2865.     rts
  2866.  
  2867. OpenDest:
  2868.     tst.b    (a5,Flag_CrunchBuf-DT)    ; If we have any packing mode on, check
  2869.     bne.b    .CheckTempFile        ; if we should use a temporary dir.
  2870.     tst.b    (a5,Flag_LhAPack-DT)
  2871.     bne.b    .CheckTempFile
  2872.     move.l    #DestName,d1        ; Open the DestName file.
  2873.  
  2874. .DoOpen:
  2875.     move.l    #MODE_NEWFILE,d2
  2876.     Call    Dos,Open
  2877.     move.l    d0,(a5,DestHandle-DT)
  2878.     beq.w    Err_NoDest
  2879.     st    (a5,Mode_DeleteErrDest-DT)
  2880.     moveq    #0,d2
  2881.     move.l    (a5,DestPointer-DT),a1
  2882.     move.l    (a5,Table-DT),a3    ; Get the table.
  2883.     lea    (a5,SpaceBuf-DT),a2
  2884.     lea    (a5,InterNetBuf-DT),a4
  2885.     rts
  2886.  
  2887. .CheckTempFile:
  2888.     lea    (a5,CrunchSrcName-DT),a0
  2889.     lea    (a5,DestName-DT),a1    ; The default is to write on the dest.
  2890.     bsr    StrCpy
  2891.     lea    (a5,TempDir-DT),a0
  2892.     move.l    #CrunchSrcName,d1
  2893.     tst.b    (a0)
  2894.     beq.b    .DoOpen            ; No TempDir, write on destination.
  2895.     lea    (a5,StrBuf-DT),a0
  2896.     lea    (a5,TempDir-DT),a1
  2897.     bsr    StrCpy
  2898.     move.l    #StrBuf,d1
  2899.     move.l    (a5,CurrentLink-DT),d2
  2900.     add.l    #fl_FileName,d2
  2901.     move.l    #256,d3
  2902.     Call    Dos,AddPart
  2903.     moveq    #4,d7
  2904.     tst.l    d0
  2905.     beq.b    CodeError
  2906.     lea    (a5,CrunchSrcName-DT),a0
  2907.     lea    (a5,StrBuf-DT),a1
  2908.     bsr    StrCpy
  2909.     move.l    #CrunchSrcName,d1
  2910.     bra.b    .DoOpen
  2911.  
  2912. MakeSourceASCII:
  2913.     lea    (a5,SourceLenASCII-DT),a0
  2914.     move.l    (a5,SourceLen-DT),d0
  2915.     bsr    Num2ASCII
  2916.     move.l    a0,(a5,SourceLenASCIIAddr-DT)
  2917.     rts
  2918.     
  2919. CalcReadRate:
  2920.     move.w    (a5,TickCount-DT),d1    ; Check the optimal read block size so
  2921.     ext.l    d1            ; we get progress reports at the user
  2922.     add.l    d1,ReadTime        ; chosen intervals.
  2923.     move.l    ReadTime,d1
  2924.     move.l    (a5,ReadBytes-DT),d0
  2925.     move.b    (a5,TickDelay-DT),d2
  2926.     IFD    Code020
  2927.     and.l    #$ff,d2
  2928.     divu.l    d1,d0            ; Bytes/tick.
  2929.     mulu.l    d2,d0            ; Bytes/sec.
  2930.     ENDC
  2931.     IFND    Code020
  2932.     and.w    #$ff,d0
  2933.     divu.w    d1,d0
  2934.     bvs.b    .Overflow
  2935.     ext.l    d0
  2936.     mulu.w    d2,d0
  2937.     ENDC
  2938.     cmp.l    #10240,d0
  2939.     bcs    .TooLow
  2940.     move.l    d0,RBlockSize
  2941.     rts
  2942.  
  2943. .TooLow:
  2944.     move.l    #10240,RBlockSize
  2945.     rts
  2946.  
  2947. .Overflow:
  2948.     move.l    #65535,d0
  2949.     mulu.w    d2,d0
  2950.     move.l    d0,RBlockSize
  2951.     rts
  2952.  
  2953. PrintStats:
  2954.     movem.l    d1-d3/a0-a1,-(sp)
  2955.     moveq    #0,d0            ; Get the signals.
  2956.     moveq    #0,d1
  2957.     Call    Exec,SetSignal
  2958.     movem.l    (sp)+,d1-d3/a0-a1
  2959.     btst    #SIGBREAKB_CTRL_C,d0    ; Check if ^C was pressed.
  2960.     bne    BreakPressed
  2961.     clr.b    (a5,Flag_StatsDue-DT)
  2962.     movem.l    d1-d7/a0-a6,-(sp)
  2963.     move.l    d3,-(sp)
  2964.     bsr    ClearPrintBuf
  2965.     move.l    #Text_Converted,a0    ; The progress info for fully buffered
  2966.     bsr    AddPrintBuf        ; input.
  2967.     lea    (a5,NumberBuf-DT),a0
  2968.     move.l    (sp)+,d0        ; The bytes converted.
  2969.     bsr    Num2ASCII
  2970.     bsr    AddPrintBuf
  2971.     move.l    #Text_Slash,a0
  2972.     bsr    AddPrintBuf
  2973.     move.l    (a5,SourceLenASCIIAddr-DT),a0
  2974.     bsr    AddPrintBuf
  2975.     move.l    #Text_ClearEOL,a0
  2976.     bsr    AddPrintBuf
  2977.     move.l    #Text_CR,a0
  2978.     bsr    AddPrintBuf
  2979.     bsr    WritePrintBuf
  2980.     movem.l    (sp)+,d1-d7/a0-a6
  2981.     rts
  2982.  
  2983. ClearVars:                ; Clear variables that may change
  2984.     lea    (a5,SpaceBuf-DT),a2    ; between different files.
  2985.     clr.l    (a5,EOLs-DT)
  2986.     clr.l    (a5,WrittenBytes-DT)
  2987.     clr.l    (a5,ReadBytes-DT)
  2988.     clr.l    (a5,LeftBytes-DT)
  2989.     clr.l    (a5,InputBytes-DT)
  2990.     clr.b    (a5,Flag_PPUsed-DT)
  2991.     clr.b    (a5,Flag_DidLhAPack-DT)
  2992.     clr.l    (a5,SpaceNumber-DT)
  2993.     clr.l    (a5,Tabs-DT)
  2994.     clr.b    (a5,PreSpace-DT)
  2995.     rts
  2996.  
  2997. ClearPrintBuf:
  2998.     move.l    #PrintBuf,(a5,PrintBufPtr-DT)
  2999.     rts
  3000.  
  3001. AddPrintBuf:                ; Add the string in A0 to PrintBuf.
  3002.     move.l    (a5,PrintBufPtr-DT),a1
  3003.  
  3004. apb_Copy:
  3005.     move.b    (a0)+,(a1)+
  3006.     bne.b    apb_Copy
  3007.     subq.l    #1,a1            ; A1 is 1 past the null. We want to
  3008.     move.l    a1,(a5,PrintBufPtr-DT)    ; overwrite the null.
  3009.     rts
  3010.  
  3011. NumPrintBuf:                ; Add the string in A0 to PrintBuf.
  3012.     move.l    (a5,PrintBufPtr-DT),a0
  3013.     bsr    StrNumCat
  3014.     move.l    (a5,PrintBufPtr-DT),a0
  3015.     bsr    StrEnd
  3016.     move.l    a0,(a5,PrintBufPtr-DT)
  3017.     rts
  3018.  
  3019. WritePrintBuf:
  3020.     move.l    #PrintBuf,d2
  3021.     bsr.b    PrintText
  3022.     rts
  3023.  
  3024. PrintText:
  3025.     move.l    d2,a0
  3026.     move.l    _DosBase,a6        ; Check if "dos.library" has been
  3027.     IFD    Code020            ; opened.
  3028.     tst.l    a6
  3029.     ENDC
  3030.     IFND    Code020
  3031.     cmp.l    #0,a6
  3032.     ENDC
  3033.     beq.b    OpenErrDos        ; If it hasn't, open a temporary
  3034.     tst.l    (a5,OutStruct-DT)    ; "dos.library".
  3035.     beq.b    OpenErrDos
  3036.  
  3037. PrintText1:
  3038.     tst.b    (a0)+            ; Find out the length of the string.
  3039.     bne.b    PrintText1
  3040.     sub.l    d2,a0
  3041.     subq.w    #1,a0
  3042.     move.l    a0,d3
  3043.     move.l    (a5,OutStruct-DT),d1
  3044.     jsr    _LVOWrite(a6)
  3045.     tst.l    _DosBase
  3046.     beq.b    CloseErrDos
  3047.     rts
  3048.  
  3049. OpenErrDos:
  3050.     movem.l    d0-d7/a0-a5,-(sp)
  3051.     lea    _DosName,a1
  3052.     moveq    #0,d0
  3053.     Call    Exec,OpenLibrary
  3054.     move.l    d0,(a5,ErrDosBase-DT)
  3055.     move.l    d0,a6
  3056.     IFD    Code020
  3057.     tst.l    a6
  3058.     ENDC
  3059.     IFD    Code020
  3060.     cmp.l    #0,a6
  3061.     ENDC
  3062.     bne.b    OpenErrDos2
  3063.     movem.l    (sp)+,d0-d7/a0-a5
  3064.     rts
  3065.  
  3066. OpenErrDos2:
  3067.     move.l    d0,a6
  3068.     jsr    _LVOOutput(a6)
  3069.     move.l    d0,(a5,OutStruct-DT)
  3070.     bne.b    OpenErrDos1
  3071.     movem.l    (sp)+,d0-d7/a0-a5
  3072.     rts
  3073.  
  3074. OpenErrDos1:
  3075.     movem.l    (sp)+,d0-d7/a0-a5
  3076.     bra.b    PrintText1
  3077.  
  3078. CloseErrDos:
  3079.     move.l    (a5,ErrDosBase-DT),a1
  3080.     Call    Exec,CloseLibrary
  3081.     rts
  3082.  
  3083. PrintTextLen:
  3084.     move.l    (a5,OutStruct-DT),d1
  3085.     Call    Dos,Write
  3086.     rts
  3087.  
  3088. ; Skips spaces in a string pointed to by A0, returns A0 as zero if it ran out
  3089. ; of string.
  3090.  
  3091. SkipSpace:
  3092.     cmp.b    #" ",(a0)
  3093.     beq.b    SkipSpace1
  3094.     rts
  3095.  
  3096. SkipSpace1:
  3097.     addq.l    #1,a0
  3098.     tst.b    (a0)
  3099.     bne.b    SkipSpace
  3100.     sub.l    a0,a0
  3101.     rts
  3102.  
  3103. FindEnd:
  3104.     cmp.b    #'"',(a0)        ; If the first letter is a quote,
  3105.     beq.b    FindEnd_Quote        ; go to FindEnd_Quote
  3106.  
  3107. FindEnd_Space:
  3108.     addq.l    #1,a0            ; Get the next position, if it is a
  3109.     cmp.b    #" ",(a0)        ; Space, we found the end
  3110.     beq.b    FindEnd_Space1
  3111.     tst.b    (a0)            ; If it's the end of comline, we found
  3112.     beq.b    FindEnd_Space1        ; the end of the name.
  3113.     bra.b    FindEnd_Space
  3114.  
  3115. FindEnd_Space1:
  3116.     subq.l    #1,a0
  3117.     rts
  3118.  
  3119. FindEnd_Quote:
  3120.     addq.l    #1,a0            ; Return the address of the first quote
  3121.     tst.b    (a0)            ; in a string in A0, or 0 for error.
  3122.     beq.b    FindEnd_Quote2
  3123.     cmp.b    #'"',(a0)
  3124.     bne.b    FindEnd_Quote
  3125.     rts
  3126.  
  3127. FindEnd_Quote2:
  3128.     sub.l    a0,a0
  3129.     rts
  3130.  
  3131.     INCDIR    "SRC:Routines/"
  3132.  
  3133.     IFD    Code020
  3134.     INCLUDE    "Num2ASCII-020.S"
  3135.     ENDC
  3136.  
  3137.     IFND    Code020
  3138.     INCLUDE    "Num2ASCII.S"
  3139.     ENDC
  3140.  
  3141.     INCLUDE    "Percentage.S"
  3142.     INCLUDE    "CopyName.S"
  3143.  
  3144. **********
  3145. ** DATA **
  3146. **********
  3147.  
  3148.     SECTION    FastData,DATA
  3149.  
  3150. MyAnchor:
  3151.     dc.l    0            ; ap_Base
  3152.     dc.l    0            ; ap_Last
  3153.     dc.l    SIGBREAKF_CTRL_C    ; ap_BreakBits
  3154.     dc.l    0            ; ap_FoundBreak
  3155.     dc.b    0            ; ap_Flags
  3156.     dc.b    0
  3157.     dc.w    256            ; ap_Strlen
  3158.     ds.b    fib_SIZEOF
  3159.     ds.b    256
  3160.  
  3161. VertBInterrupt:
  3162.     dc.l    0            ; Successor.
  3163.     dc.l    0            ; Predecessor.
  3164.     dc.b    NT_INTERRUPT        ; Type.
  3165.     dc.b    0            ; Pri.
  3166.     dc.l    Text_VertBIntName    ; Ptr to name.
  3167.     dc.l    TimeCounter        ; Ptr to TimeCounter, IS_DATA.
  3168.     dc.l    VertBIntCode        ; Ptr to VBLANK code.
  3169.  
  3170. RBlockSize:                ; Bytes of data for a single Read().
  3171.     dc.l    10240
  3172.  
  3173. LhATagList:
  3174.     dc.l    TAG_END,TAG_END
  3175.  
  3176. ReadTime:                ; Time taken in all Read()'s.
  3177.     dc.l    1
  3178.  
  3179. ***********************
  3180. ** Conversion tables **
  3181. ***********************
  3182.  
  3183. Table_ToPC:
  3184.     dc.b    $00,$00,$00,$00,$00,$00,$00,$00,$00,$09,$0A,$00,$00,$00,$00,$00 ;00
  3185.     dc.b    $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$1b,$00,$00,$00,$00 ;10
  3186.     dc.b    " ","!",'"',"#","$","%","&","'","(",")","*","+",",","-",".","/" ;20
  3187.     dc.b    "0","1","2","3","4","5","6","7","8","9",":",";","<","=",">","?" ;30
  3188.     dc.b    "@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O" ;40
  3189.     dc.b    "P","Q","R","S","T","U","V","W","X","Y","Z","[","\\","]","^","_" ;50
  3190.     dc.b    "`","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o" ;60
  3191.     dc.b    "p","q","r","s","t","u","v","w","x","y","z","{","|","}","~",$B1
  3192.     dc.b    $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
  3193.     dc.b    $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$9b,$00,$00,$00,$00 ;90
  3194.     dc.b    " ",$AD,$9B,$9C,"$",$9D,"|",$15,'"',"C",$A6,$AE,$AA,"-","R","-"
  3195.     dc.b    $F8,$F1,$FD,"3","'",$E6,$14,$F9,",","1",$A7,$AF,$AC,$AB,"3",$A8
  3196.     dc.b    $85,$A0,$8F,"A",$8E,$8F,$92,$80,$8A,$90,$88,$89,$8D,$A1,$8C,$8B
  3197.     dc.b    "D","N",$95,$A2,$93,"O",$99,"x","0",$97,$A3,$96,$9A,"Y","B",$E1
  3198.     dc.b    $85,$A0,"a","a",$84,$83,$91,$87,$8A,$82,$88,$89,$8D,$A1,$8C,$8B
  3199.     dc.b    $EB,"n",$95,$A2,$93,"o",$94,$F6,"0",$97,$A3,$96,$81,"y","B",$98
  3200.  
  3201. Table_Null:
  3202.     dc.b    $00,$00,$00,$00,$00,$00,$00,$00,$00,$09,$0A,$00,$00,$00,$00,$00 ;10
  3203.     dc.b    $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$1b,$00,$00,$00,$00 ;10
  3204.     dc.b    " ","!",'"',"#","$","%","&","'","(",")","*","+",",","-",".","/"
  3205.     dc.b    "0","1","2","3","4","5","6","7","8","9",":",";","<","=",">","?"
  3206.     dc.b    "@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O"
  3207.     dc.b    "P","Q","R","S","T","U","V","W","X","Y","Z","[","\\","]","^","_"
  3208.     dc.b    "`","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o"
  3209.     dc.b    "p","q","r","s","t","u","v","w","x","y","z","{","|","}","~",$7F
  3210.     dc.b    $80,$81,$82,$83,$84,$85,$86,$87,$88,$89,$8A,$8B,$8C,$8D,$8E,$8F
  3211.     dc.b    $90,$91,$92,$93,$94,$95,$96,$97,$98,$99,$9A,$9B,$9C,$9D,$9E,$9F
  3212.     dc.b    $A0,"¡","¢","£","¤","¥","¦","§","¨","©","ª","«","¬","­","®","¯"
  3213.     dc.b    "°","±","²","³","´","µ","¶","·","¸","¹","º","»","¼","½","¾","¿"
  3214.     dc.b    "À","Á","Â","Ã","Ä","Å","Æ","Ç","È","É","Ê","Ë","Ì","Í","Î","Ï"
  3215.     dc.b    "Ð","Ñ","Ò","Ó","Ô","Õ","Ö","×","Ø","Ù","Ú","Û","Ü","Ý","Þ","ß"
  3216.     dc.b    "à","á","â","ã","ä","å","æ","ç","è","é","ê","ë","ì","í","î","ï"
  3217.     dc.b    "ð","ñ","ò","ó","ô","õ","ö","÷","ø","ù","ú","û","ü","ý","þ","ÿ"
  3218.  
  3219. Table_Lowercase:
  3220.     dc.b    $00,$00,$00,$00,$00,$00,$00,$00,$00,$09,$0A,$00,$00,$00,$00,$00 ;10
  3221.     dc.b    $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$1b,$00,$00,$00,$00 ;10
  3222.     dc.b    " ","!",'"',"#","$","%","&","'","(",")","*","+",",","-",".","/"
  3223.     dc.b    "0","1","2","3","4","5","6","7","8","9",":",";","<","=",">","?"
  3224.     dc.b    "@","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o"
  3225.     dc.b    "p","q","r","s","t","u","v","w","x","y","z","[","\\","]","^","_"
  3226.     dc.b    "`","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o"
  3227.     dc.b    "p","q","r","s","t","u","v","w","x","y","z","{","|","}","~",$7F
  3228.     dc.b    $80,$81,$82,$83,$84,$85,$86,$87,$88,$89,$8A,$8B,$8C,$8D,$8E,$8F
  3229.     dc.b    $90,$91,$92,$93,$94,$95,$96,$97,$98,$99,$9A,$9B,$9C,$9D,$9E,$9F
  3230.     dc.b    $A0,"¡","¢","£","¤","¥","¦","§","¨","©","ª","«","¬","­","®","¯"
  3231.     dc.b    "°","±","²","³","´","µ","¶","·","¸","¹","º","»","¼","½","¾","¿"
  3232.     DC.B    "à","á","â","ã","ä","å","æ","ç","è","é","ê","ë","ì","í","î","ï"
  3233.     dc.b    "ð","ñ","ò","ó","ô","õ","ö","÷","ø","ù","ú","û","ü","ý","þ","ß"
  3234.     dc.b    "à","á","â","ã","ä","å","æ","ç","è","é","ê","ë","ì","í","î","ï"
  3235.     dc.b    "ð","ñ","ò","ó","ô","õ","ö","÷","ø","ù","ú","û","ü","ý","þ","ÿ"
  3236.  
  3237. Table_Uppercase:
  3238.     dc.b    $00,$00,$00,$00,$00,$00,$00,$00,$00,$09,$0A,$00,$00,$00,$00,$00 ;10
  3239.     dc.b    $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$1b,$00,$00,$00,$00 ;10
  3240.     dc.b    " ","!",'"',"#","$","%","&","'","(",")","*","+",",","-",".","/"
  3241.     dc.b    "0","1","2","3","4","5","6","7","8","9",":",";","<","=",">","?"
  3242.     dc.b    "@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O"
  3243.     dc.b    "P","Q","R","S","T","U","V","W","X","Y","Z","[","\\","]","^","_"
  3244.     dc.b    "`","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O"
  3245.     dc.b    "P","Q","R","S","T","U","V","W","X","Y","Z","{","|","}","~",$7F
  3246.     dc.b    $80,$81,$82,$83,$84,$85,$86,$87,$88,$89,$8A,$8B,$8C,$8D,$8E,$8F
  3247.     dc.b    $90,$91,$92,$93,$94,$95,$96,$97,$98,$99,$9A,$9B,$9C,$9D,$9E,$9F
  3248.     dc.b    $A0,"¡","¢","£","¤","¥","¦","§","¨","©","ª","«","¬","­","®","¯"
  3249.     dc.b    "°","±","²","³","´","µ","¶","·","¸","¹","º","»","¼","½","¾","¿"
  3250.     dc.b    "À","Á","Â","Ã","Ä","Å","Æ","Ç","È","É","Ê","Ë","Ì","Í","Î","Ï"
  3251.     dc.b    "Ð","Ñ","Ò","Ó","Ô","Õ","Ö","×","Ø","Ù","Ú","Û","Ü","Ý","Þ","ß"
  3252.     dc.b    "À","Á","Â","Ã","Ä","Å","Æ","Ç","È","É","Ê","Ë","Ì","Í","Î","Ï"
  3253.     dc.b    "Ð","Ñ","Ò","Ó","Ô","Õ","Ö","×","Ø","Ù","Ú","Û","Ü","Ý","Þ","ÿ"
  3254.  
  3255. Table_ToSF7:
  3256.     dc.b    $00,$00,$00,$00,$00,$00,$00,$00,$00,$09,$0A,$00,$00,$00,$00,$00 ;10
  3257.     dc.b    $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$1b,$00,$00,$00,$00 ;10
  3258.     dc.b    " ","!",'"',"#","$","%","&","'","(",")","*","+",",","-",".","/"
  3259.     dc.b    "0","1","2","3","4","5","6","7","8","9",":",";","<","=",">","?"
  3260.     dc.b    "@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O"
  3261.     dc.b    "P","Q","R","S","T","U","V","W","X","Y","Z","[","\\","]","^","_"
  3262.     dc.b    "`","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o"
  3263.     dc.b    "p","q","r","s","t","u","v","w","x","y","z","{","|","}","~",$7F
  3264.     dc.b    $80,$81,$82,$83,$84,$85,$86,$87,$88,$89,$8A,$8B,$8C,$8D,$8E,$8F
  3265.     dc.b    $90,$91,$92,$93,$94,$95,$96,$97,$98,$99,$9A,$9B,$9C,$9D,$9E,$9F
  3266.     dc.b    $A0,"¡","¢","£","¤","¥","¦","§","¨","©","ª","«","¬","­","®","¯"
  3267.     dc.b    "°","±","²","³","´","µ","¶","·","¸","¹","º","»","¼","½","¾","¿"
  3268.     dc.b    "À","Á","Â","Ã","[","Å","Æ","Ç","È","É","Ê","Ë","Ì","Í","Î","Ï"
  3269.     dc.b    "Ð","Ñ","Ò","Ó","Ô","Õ","\\","×","Ø","Ù","Ú","Û","Ü","Ý","Þ","ß"
  3270.     dc.b    "à","á","â","ã","{","å","æ","ç","è","é","ê","ë","ì","í","î","ï"
  3271.     dc.b    "ð","ñ","ò","ó","ô","õ","|","÷","ø","ù","ú","û","ü","ý","þ","ÿ"
  3272.  
  3273. Table_FromSF7:
  3274.     dc.b    $00,$00,$00,$00,$00,$00,$00,$00,$00,$09,$0A,$00,$00,$00,$00,$00 ;10
  3275.     dc.b    $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$1b,$00,$00,$00,$00 ;10
  3276.     dc.b    " ","!",'"',"#","$","%","&","'","(",")","*","+",",","-",".","/"
  3277.     dc.b    "0","1","2","3","4","5","6","7","8","9",":",";","<","=",">","?"
  3278.     dc.b    "@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O"
  3279.     dc.b    "P","Q","R","S","T","U","V","W","X","Y","Z","Ä","Ö","Å","^","_"
  3280.     dc.b    "`","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o"
  3281.     dc.b    "p","q","r","s","t","u","v","w","x","y","z","ä","ö","å","~",$7F
  3282.     dc.b    $80,$81,$82,$83,$84,$85,$86,$87,$88,$89,$8A,$8B,$8C,$8D,$8E,$8F
  3283.     dc.b    $90,$91,$92,$93,$94,$95,$96,$97,$98,$99,$9A,$9B,$9C,$9D,$9E,$9F
  3284.     dc.b    $A0,"¡","¢","£","¤","¥","¦","§","¨","©","ª","«","¬","­","®","¯"
  3285.     dc.b    "°","±","²","³","´","µ","¶","·","¸","¹","º","»","¼","½","¾","¿"
  3286.     dc.b    "À","Á","Â","Ã","Ä","Å","Æ","Ç","È","É","Ê","Ë","Ì","Í","Î","Ï"
  3287.     dc.b    "Ð","Ñ","Ò","Ó","Ô","Õ","Ö","×","Ø","Ù","Ú","Û","Ü","Ý","Þ","ß"
  3288.     dc.b    "à","á","â","ã","ä","å","æ","ç","è","é","ê","ë","ì","í","î","ï"
  3289.     dc.b    "ð","ñ","ò","ó","ô","õ","ö","÷","ø","ù","ú","û","ü","ý","þ","ÿ"
  3290.  
  3291. ; df is the upper block.
  3292. ; dc is the lower block.
  3293.  
  3294. Table_FromPC:    ;0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
  3295.     dc.b    $00,$00,$00,$00,$00,$00,$00,$00,$00,$09,$0a,$00,$00,$00,$00,$00 ;00
  3296.     dc.b    $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$1b,$00,$00,$00,$00 ;10
  3297.     dc.b    " ","!",'"',"#","$","%","&","'","(",")","*","+",",","-",".","/" ;20
  3298.     dc.b    "0","1","2","3","4","5","6","7","8","9",":",";","<","=",">","?" ;30
  3299.     dc.b    "@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O" ;40
  3300.     dc.b    "P","Q","R","S","T","U","V","W","X","Y","Z","[","\\","]","^","_" ;50
  3301.     dc.b    "`","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o" ;60
  3302.     dc.b    "p","q","r","s","t","u","v","w","x","y","z","{","|","}","~","" ;70
  3303.     dc.b    "Ç","ü","é","å","ä","à","å","ç","ê","ë","è","ï","î","ì","Ä","Å" ;80
  3304.     dc.b    "È","æ","Æ","ô","ö","ò","û","ù","ÿ","Ö","Ü",$a2,"£",$a5,"P","f" ;90
  3305.     dc.b    "á","í","ó","ú","ñ","Ñ","ª","º","¿",".",".","½","¼","¡","«","»" ;A0
  3306.     dc.b    $7f,$7f,$7f,"|","+","#","+",".","#","#","|","#","#","'","#","." ;B0
  3307.     dc.b    "`","+","+","+","-","+","#","+","#","#","#","#","#","=","#","#" ;C0
  3308.     dc.b    "+","#","+","`","#","#",".","+","#","'",".",$7f,"o","[","]","°" ;D0
  3309.     dc.b    "c","ß","r","+","E","ó",$b5,"i","o","0","O","ð","ø","ø","E","A" ;E0
  3310.     dc.b    "=","±",">","<","í","j","÷","~","°","·","·","V","n","²","·"," " ;F0
  3311.  
  3312. Table_Combined:    ;0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
  3313.     dc.b    $00,$00,$00,$00,$00,$00,$00,$00,$00,$09,$0a,$00,$00,$00,$00,$00 ;00
  3314.     dc.b    $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$1b,$00,$00,$00,$00 ;10
  3315.     dc.b    " ","!",'"',"#","$","%","&","'","(",")","*","+",",","-",".","/" ;20
  3316.     dc.b    "0","1","2","3","4","5","6","7","8","9",":",";","<","=",">","?" ;30
  3317.     dc.b    "@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O" ;40
  3318.     dc.b    "P","Q","R","S","T","U","V","W","X","Y","Z","Ä","Ö","Å","^","_" ;50
  3319.     dc.b    "`","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o" ;60
  3320.     dc.b    "p","q","r","s","t","u","v","w","x","y","z","ä","ö","å","~","" ;70
  3321.     dc.b    "Ç","ü","é","å","ä","à","å","ç","ê","ë","è","ï","î","ì","Ä","Å" ;80
  3322.     dc.b    "È","æ","Æ","ô","ö","ò","û","ù","ÿ","Ö","Ü",$a2,"£",$a5,"P","f" ;90
  3323.     dc.b    "á","í","ó","ú","ñ","Ñ","ª","º","¿",".",".","½","¼","¡","«","»" ;A0
  3324.     dc.b    $7f,$7f,$7f,"|","+","#","+",".","#","#","|","#","#","'","#","." ;B0
  3325.     dc.b    "`","+","+","+","-","+","#","+","#","#","#","#","#","=","#","#" ;C0
  3326.     dc.b    "+","#","+","`","#","#",".","+","#","'",".",$7f,"æ","[","]","^" ;D0
  3327.     dc.b    "c","ß","r","+","E","ó",$b5,"i","o","0","O","ð","ø","ø","E","A" ;E0
  3328.     dc.b    "=","±",">","<","í","j","÷","~","°","·","·","V","n","²","·"," " ;F0
  3329.  
  3330.     INCDIR    "SRC:Port/"
  3331.  
  3332.     IFD    Code020
  3333.  
  3334. CapRange:
  3335.     dc.b    "A"
  3336.     dc.b    "Z"
  3337.  
  3338. LowRange:
  3339.     dc.b    "a"
  3340.     dc.b    "z"
  3341.  
  3342.     ENDC
  3343.  
  3344. Flag_DestName:                ; We have a real destination.
  3345.     dc.b    $ff
  3346.  
  3347. _DosName:
  3348.     dc.b    "dos.library",0
  3349.  
  3350. PPName:
  3351.     PPNAME
  3352.  
  3353. PrefName:
  3354.     dc.b    "ENV:Port.Prefs\0"
  3355.  
  3356. ***********
  3357. ** TEXTS **
  3358. ***********
  3359.  
  3360. Text_VertBIntName:
  3361.     dc.b    "Port VBlank Timer",0
  3362.  
  3363. Text_CodeError:
  3364.     INCBIN    "PortCodeError"
  3365.     dc.b    0
  3366.  
  3367. Text_HelpText:
  3368.     INCBIN    "PortOpts1"
  3369.     dc.b    0
  3370.  
  3371. Text_Credits:
  3372.     INCBIN    "PortOpts2"
  3373.     dc.b    0
  3374.  
  3375. Text_Header:
  3376.     INCBIN    "Port.Header"
  3377.     dc.b    0
  3378.  
  3379. Text_CursorOff:
  3380.     dc.b    "\c0 p",0
  3381.  
  3382. Text_CursorOn:
  3383.     dc.b    "\c1 p",0
  3384.  
  3385. Text_Error:
  3386.     dc.b    "Error!  ",0
  3387.  
  3388. Text_Warning:
  3389.     dc.b    "Warning:  ",0
  3390.  
  3391. ; These need the LF even though they are error messages, because there must
  3392. ; be one LF between the messages of each different file.
  3393.  
  3394. Text_CrunchReadWrite:
  3395.     dc.b    "Could not read/write the file for PowerPacking\n\0"
  3396.  
  3397. Text_NoCrunchMem:
  3398.     dc.b    "Not enough memory for PowerPacking.\n\0"
  3399.  
  3400. Text_CrunchOverflow:
  3401.     dc.b    "Buffer overflow.  File was not PowerPacked.\n\0"
  3402.  
  3403. Text_NoCrunchFile:
  3404.     dc.b    "Could not lock the file for PowerPacking.\n\0"
  3405.  
  3406. Text_NeedBufPP:
  3407.     dc.b    "Cannot use NoBuffer mode with PowerPacked files.\0"
  3408.  
  3409. Text_Decrunching:
  3410.     dc.b    "Loading & decrunching a PowerPacked file...\n\0"
  3411.  
  3412. Text_UnknownPP:
  3413.     dc.b    "The file is packed with an unknown version of PowerPacker.\0"
  3414.  
  3415. Text_WrongPass:
  3416.     dc.b    "Incorrect password, can't decrypt.\0"
  3417.  
  3418. Text_FileDest:
  3419.     dc.b    "Can't have a file destination for wildcards.\0"
  3420.  
  3421.     IFD    Code020
  3422.  
  3423. Text_OldProcessor:
  3424.     dc.b    "At least 68020 is needed.\0"
  3425.  
  3426.     ENDC
  3427.  
  3428. Text_NewKickNeed:
  3429.     dc.b    "At least system V37 is needed.\0"
  3430.  
  3431. Text_PrefsError:
  3432.     dc.b    "Error reading preferences, defaults used.\n\n\0"
  3433.  
  3434. Text_BadComLine:
  3435.     dc.b    "Bad commandline.",0
  3436.  
  3437. Text_Reading:
  3438.     dc.b    "Reading...\0"
  3439.  
  3440. Text_Writing:
  3441.     dc.b    "Writing...\0"
  3442.  
  3443. Text_ANSIStrip:
  3444.     dc.b    "ANSIStrip\0"
  3445.  
  3446. Text_MakeEOLs:
  3447.     dc.b    "MakeEOLs\0"
  3448.  
  3449. Text_INStrip:
  3450.     dc.b    "InterNetStrip\0"
  3451.  
  3452. Text_EndSpaceRemoval:
  3453.     dc.b    "EndSpaceRemoval\0"
  3454.  
  3455. Text_PowerPackOutput:
  3456.     dc.b    "PowerPackOutput\0"
  3457.  
  3458. Text_SpacesToTabs:
  3459.     dc.b    "SpacesToTabs\0"
  3460.  
  3461. Text_TabsToSpaces:
  3462.     dc.b    "TabsToSpaces\0"
  3463.  
  3464. Text_TickDelay:
  3465.     dc.b    "TickDelay\0"
  3466.  
  3467. Text_TempDir:
  3468.     dc.b    "TempDir\0"
  3469.  
  3470. Text_LhAPack:
  3471.     dc.b    "LhAPack\0"
  3472.  
  3473. Text_INFrom:
  3474.     dc.b    "From \0"
  3475.  
  3476. Text_INPath:
  3477.     dc.b    "Path: \0"
  3478.  
  3479. Text_UnknownOpt:
  3480.     dc.b    "Unknown preferences option \"\0"
  3481.  
  3482. Text_BadOptArg:
  3483.     dc.b    "Bad argument for preferences option \"\0"
  3484.  
  3485. Text_ConvBuf:
  3486.     dc.b    "ConversionBuffer\0"
  3487.  
  3488. Text_NoSource:
  3489.     dc.b    "Could not open source file.",0
  3490.  
  3491. Text_NoDest:
  3492.     dc.b    "Could not open destination file.",0
  3493.  
  3494. Text_SourceIsDir:
  3495.     dc.b    "Source cannot be a directory.",0
  3496.  
  3497. Text_WriteFail:
  3498.     dc.b    "Can't write data.",0
  3499.  
  3500. Text_NoComLineSpace:
  3501.     dc.b    "The mode must be separated with at least one space.",0
  3502.  
  3503. Text_BadLogic:
  3504.     dc.b    "Conflicting options.",0
  3505.  
  3506. Text_OptConflict:
  3507.     dc.b    "Conflicting options in preferences.",0
  3508.  
  3509. Text_NoMemConvert:
  3510.     dc.b    "Not enough memory to convert the file.",0
  3511.  
  3512. Text_NoMemory:
  3513.     dc.b    "Not enough memory to load the file.",0
  3514.  
  3515. Text_PowerPacked:
  3516.     dc.b    "File is a PowerPacked, \"powerpacker.library\" is needed to read.\0"
  3517.  
  3518. Text_PowerPackNeed:
  3519.     dc.b    "\"powerpacker.library\" V35+ is required.\0"
  3520.  
  3521. Text_BadSource:
  3522.     dc.b    "Source file corrupted.",0
  3523.  
  3524. Text_BadDest:
  3525.     dc.b    "Destination corrupted.",0
  3526.  
  3527. Text_Crunching1:
  3528.     dc.b    "Packing \"\0"
  3529.  
  3530. Text_INRemoved:
  3531.     dc.b    "\nHEADER-REMOVED--HEADER-REMOVED--HEADER-REMOVED--HEADER-REMOVED--HEADER REMOVED\n\n",0
  3532.  
  3533. Text_Deleted:
  3534.     dc.b    '" deleted.\n\0'
  3535.  
  3536. Text_ConvFile1:
  3537.     dc.b    "Converting file \"\0"
  3538.  
  3539. Text_Crunching2:
  3540. Text_ConvFile2:
  3541.     dc.b    "\"...\n\0"
  3542.  
  3543. Text_Done:
  3544.     dc.b    "Done: \0"
  3545.  
  3546. Text_Gain:
  3547.     dc.b    "  Gain: \0"
  3548.  
  3549. Text_Input:
  3550.     dc.b    "Input: ",0
  3551.  
  3552. Text_Output:
  3553.     dc.b    "  Output: ",0
  3554.  
  3555. Text_Read:
  3556.     dc.b    "Read: ",0
  3557.  
  3558. Text_Converted:
  3559.     dc.b    "Converted: ",0
  3560.  
  3561. Text_Checking:
  3562.     dc.b    "Checking file type...\c0K\r\0"
  3563.  
  3564. Text_LhALine:
  3565.     dc.b    "LhA r ",0
  3566.  
  3567. Text_LhASuffix:
  3568.     dc.b    ".LHA",0
  3569.  
  3570. Text_Break:
  3571.     dc.b    "-BREAK-\c0K\n\0"
  3572.  
  3573. Text_ClearEOL:
  3574.     dc.b    "\c0K\0"
  3575.  
  3576. Text_AmigaSuf:
  3577.     dc.b    ".AMY\0"
  3578.  
  3579. Text_PCSuf:
  3580.     dc.b    ".PC\0"
  3581.  
  3582. Text_SF7Suf:
  3583.     dc.b    ".SF7\0"
  3584.  
  3585. Text_CR:
  3586.     dc.b    CR,0
  3587.  
  3588. Text_LF:
  3589.     dc.b    LF,0
  3590.  
  3591. Text_Final:
  3592.     dc.b    "File size change: \0"
  3593.  
  3594. Text_NegSign:
  3595.     dc.b    "-",0
  3596.  
  3597. Text_PosSign:
  3598.     dc.b    "+",0
  3599.  
  3600. Text_PercentSign:
  3601.     dc.b    "%\c0K\0"
  3602.  
  3603. Text_DoubleSpace:
  3604.     dc.b    " "
  3605. Text_Space:
  3606.     dc.b    " ",0
  3607.  
  3608. Text_Slash:
  3609.     dc.b    "/",0
  3610.  
  3611. Text_Period:
  3612.     dc.b    ".",0
  3613.  
  3614. Text_Quote:
  3615.     dc.b    '"',0
  3616.  
  3617.  
  3618.     SECTION    FastBlank,BSS
  3619.  
  3620. DT:                    ; Section base address.
  3621.  
  3622. FIB:
  3623.     ds.b    fib_SIZEOF
  3624.  
  3625. ErrorCode:                ; Port return code.
  3626.     ds.l    1
  3627.  
  3628. OldFileLinkPtr:                ; Ptr to the next to last (last) 'Link.
  3629.     ds.l    1
  3630.  
  3631. PrefDecode:                ; Ptr to the current place in data.
  3632.     ds.l    1
  3633.  
  3634. PrefPtr:                ; Ptr to loaded preferences data.
  3635.     ds.l    1
  3636.  
  3637. Size_Prefs:                ; Size of the loaded preferences data.
  3638.     ds.l    1
  3639.  
  3640. PrefHandle:                ; Preferences file handle.
  3641.     ds.l    1
  3642.  
  3643. BigBufPtr:                ; Ptr for conversion buffer(s).
  3644.     ds.l    1
  3645.  
  3646. BigBufSize:                ; Size of the conversion buffer(s).
  3647.     ds.l    1
  3648.  
  3649. TempBuf:                ; Buffer for checking PP 4 byte ID.
  3650.     ds.l    1
  3651.  
  3652. CrDestSize:                ; Size of the packed buffer.
  3653.     ds.l    1
  3654.  
  3655. CrCrunchInfo:                ; Ptr to PP CrunchInfo structure.
  3656.     ds.l    1
  3657.  
  3658. CrBuf:                    ; Ptr to the buffer to crunch.
  3659.     ds.l    1
  3660.  
  3661. CrFile:                    ; File handle for file to crunch.
  3662.     ds.l    1
  3663.  
  3664. CrSize:                    ; Size of the file to be crunched.
  3665.     ds.l    1
  3666.  
  3667. FileLinkBase:                ; Pointer to the first FileLink.
  3668.     ds.l    1
  3669.  
  3670. CurrentLink:                ; Pointer to the current FileLink.
  3671.     ds.l    1
  3672.  
  3673. ErrDosBase:                ; DosBase used in case of error.
  3674.     ds.l    1
  3675.  
  3676. PrintBufPtr:
  3677.     ds.l    1
  3678.  
  3679. OldStack:
  3680.     ds.l    1
  3681.  
  3682. SourceLock:
  3683.     ds.l    1
  3684.  
  3685. DestLock:
  3686.     ds.l    1
  3687.  
  3688. EOLs:
  3689.     ds.l    1
  3690.  
  3691. Table:                    ; Ptr to the current translation table.
  3692.     ds.l    1
  3693.  
  3694. SourceLen:                ; Size of the source file in bytes.
  3695.     ds.l    1
  3696.  
  3697. Tabs:                    ; Counter of buffered tabs.
  3698.     ds.l    1
  3699.  
  3700. WrittenBytes:
  3701.     ds.l    1
  3702.  
  3703. ReadBytes:
  3704.     ds.l    1
  3705.  
  3706. LeftBytes:
  3707.     ds.l    1
  3708.  
  3709. InputBytes:
  3710.     ds.l    1
  3711.  
  3712. SourceHandle:
  3713.     ds.l    1
  3714.  
  3715. DestHandle:
  3716.     ds.l    1
  3717.  
  3718. OutStruct:
  3719.     ds.l    1
  3720.  
  3721. DestNStart:
  3722.     ds.l    1
  3723.  
  3724. SourceNameStart:
  3725.     ds.l    1
  3726.  
  3727. SourceNameEnd:
  3728.     ds.l    1
  3729.  
  3730. SourceNameLen:
  3731.     ds.l    1
  3732.  
  3733. _DosBase:
  3734.     ds.l    1
  3735.  
  3736. _PPBase:
  3737.     ds.l    1
  3738.  
  3739. SpaceNumber:
  3740.     ds.l    1
  3741.  
  3742. SourceLenASCIIAddr:
  3743.     ds.l    1
  3744.  
  3745. SourcePointer:                ; Ptr to the read buffer.
  3746.     ds.l    1
  3747.  
  3748. DestPointer:                ; Ptr to the write buffer.
  3749.     ds.l    1
  3750.  
  3751. Size_SrcBuf:                ; Size of the read buffer.
  3752.     ds.l    1
  3753.  
  3754. Size_DstBuf:                ; Size of the write buffer.
  3755.     ds.l    1
  3756.  
  3757. MakeNameLen:                ; MakeLhAName length.
  3758.     ds.w    1
  3759.  
  3760. INBufSize:                ; Number of bytes buffered by INStrip.
  3761.     ds.w    1
  3762.  
  3763. Col:
  3764.     ds.w    1
  3765.  
  3766. ; VBLANK interrupt's IS_DATA.
  3767.  
  3768. TimeCounter:                ; Frame counter.
  3769.     ds.b    1
  3770. TickDelay:                ; Update tick delay.
  3771.     ds.b    1
  3772. Flag_StatsDue:                ; Statistics due -flag.
  3773.     ds.b    1
  3774.     ds.b    1            ; Padding.
  3775. TickCount:                ; VB counter for read sync.
  3776.     ds.w    1
  3777.  
  3778. RealSourceName:
  3779.     ds.b    108            ; Max filename size in FIB
  3780.  
  3781. CopySymBuf:                ; Buffer for CopySymbol.
  3782.     ds.b    160
  3783.  
  3784. CrunchSrcName:                ; Name of the file to crunch.
  3785.     ds.b    256
  3786.  
  3787. TempDir:                ; Name of the temporary directory.
  3788.     ds.b    256
  3789.  
  3790. StrBuf:
  3791.     ds.b    256
  3792.  
  3793. SourceName:
  3794.     ds.b    256
  3795.  
  3796. DestName:
  3797.     ds.b    256
  3798.  
  3799. PrintBuf:
  3800.     ds.b    256
  3801.  
  3802.     IFD    Debug
  3803.  
  3804. DebugBuf:
  3805.     ds.b    256
  3806.  
  3807.     ENDC
  3808.  
  3809. SpaceBuf:
  3810.     ds.b    1024
  3811.  
  3812. InterNetBuf:
  3813.     ds.b    1024
  3814.  
  3815. NumberBuf:
  3816.     ds.b    11
  3817.  
  3818. ReadASCII:
  3819.     ds.b    11
  3820.  
  3821. SourceLenASCII:
  3822.     ds.b    11
  3823.  
  3824. Flag_IntActive:                ; VBLANK interrupt is active.
  3825.     ds.b    1
  3826.  
  3827. Flag_AnchorUsed:            ; Indicates that we need to MatchEnd().
  3828.     ds.b    1
  3829.  
  3830. Flag_Stop:                ; Indicates that exit should be taken.
  3831.     ds.b    1
  3832.  
  3833. Flag_FileFound:                ; At least one file was found.
  3834.     ds.b    1
  3835.  
  3836. Flag_PPUsed:                ; PowerPacker library was used to load
  3837.     ds.b    1            ; the file.
  3838.  
  3839. Flag_CrunchBuf:                ; PowerPack the output file.
  3840.     ds.b    1
  3841.  
  3842. Flag_LhAPack:                ; LhA pack the output file.
  3843.     ds.b    1
  3844.  
  3845. Flag_AStrip:                ; Strip ANSI codes.
  3846.     ds.b    1
  3847.  
  3848. Flag_CrunchTried:            ; Already tried crunching this file.
  3849.     ds.b    1
  3850.  
  3851. Flag_INStrip:                ; Strip InterNet headers.
  3852.     ds.b    1            ; 1-"HEADER STRIPPED" 2-Nothing.
  3853.  
  3854. Flag_INStripActive:            ; Current data is of the header.
  3855.     ds.b    1
  3856.  
  3857. Flag_ANSIState:                ; Are we waiting for a CSI etc.
  3858.     ds.b    1
  3859.  
  3860. Flag_DidLhAPack:            ; The file was really packed, safe to
  3861.     ds.b    1            ; delete the source if NoDest.
  3862.  
  3863. Mode:
  3864.     ds.b    1
  3865.  
  3866. TabSize:
  3867.     ds.b    1
  3868.  
  3869. SpaceSize:
  3870.     ds.b    1
  3871.  
  3872. Size_MakeEOLs:
  3873.     ds.b    1
  3874.  
  3875. PreSpace:
  3876.     ds.b    1
  3877.  
  3878. Mode_NoCutSpace:
  3879.     ds.b    1
  3880.  
  3881. Mode_NoBuffer:
  3882.     ds.b    1
  3883.  
  3884. Mode_DeleteErrDest:
  3885.     ds.b    1
  3886.  
  3887. Mode_SrcDeleted:
  3888.     ds.b    1
  3889.